【问题标题】:`url_serde` asking for unrelated trait bounds`url_serde` 要求不相关的特征界限
【发布时间】:2020-08-30 06:22:34
【问题描述】:

使用 serdeurl_serde 板条箱时,我收到错误提示我需要满足不相关的特征界限:

   Compiling ser v0.1.0 (/data/scratch/ser)
error[E0277]: the trait bound `for<'a> url_serde::Ser<'a, url::Url>: a::_::_serde::Serialize` is not satisfied
  --> src/b.rs:4:10
   |
4  | #[derive(Serialize, Deserialize)]
   |          ^^^^^^^^^ the trait `for<'a> a::_::_serde::Serialize` is not implemented for `url_serde::Ser<'a, url::Url>`
   | 
  ::: /home/danj/.cargo/registry/src/github.com-1ecc6299db9ec823/url_serde-0.2.0/src/lib.rs:77:46
   |
77 |     where S: Serializer, for<'a> Ser<'a, T>: Serialize
   |                                              --------- required by this bound in `url_serde::serialize`
   |
   = help: the following implementations were found:
             <url_serde::Ser<'a, std::option::Option<url::Url>> as a::_::_serde::Serialize>
             <url_serde::Ser<'a, url::Url> as a::_::_serde::Serialize>
             <url_serde::Ser<'a, url::host::Host<String>> as a::_::_serde::Serialize>
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `url_serde::De<url::Url>: a::_::_serde::Deserialize<'_>` is not satisfied
   --> src/b.rs:4:21
    |
4   | #[derive(Serialize, Deserialize)]
    |                     ^^^^^^^^^^^ the trait `a::_::_serde::Deserialize<'_>` is not implemented for `url_serde::De<url::Url>`
    | 
   ::: /home/danj/.cargo/registry/src/github.com-1ecc6299db9ec823/url_serde-0.2.0/src/lib.rs:158:40
    |
158 |     where D: Deserializer<'de>, De<T>: Deserialize<'de>
    |                                        ---------------- required by this bound in `url_serde::deserialize`
    |
    = help: the following implementations were found:
              <url_serde::De<std::option::Option<url::Url>> as a::_::_serde::Deserialize<'de>>
              <url_serde::De<url::Url> as a::_::_serde::Deserialize<'de>>
              <url_serde::De<url::host::Host> as a::_::_serde::Deserialize<'de>>
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
error: could not compile `ser`.

To learn more, run the command again with --verbose.

Cargo.toml

[package]
name = "ser"
version = "0.1.0"
authors = ["..."]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.115", features = ["derive"] }
url = "2.1.1"
url_serde = "0.2.0"

src/lib.rs

pub mod a;
pub mod b;

src/a.rs

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct A {
    pub name: String,
}

src/b.rs

use serde::{Deserialize, Serialize};
use url::Url;

#[derive(Serialize, Deserialize)]
pub struct B {
    #[serde(with = "url_serde")]
    uri: Url,
}

【问题讨论】:

    标签: url rust serde


    【解决方案1】:

    通过链接到升级的 crates.io 找到这个:https://github.com/servo/rust-url/blob/b03895bd479d72c75600dc09c8c7906f5ee203ea/UPGRADING.md

    tl;博士

    url = { version = "2.0", features = ["serde"] } 并删除对url_serde的所有引用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-27
      • 2015-09-05
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 2021-10-20
      相关资源
      最近更新 更多