如何解决url_serde要求不相关的特征范围
使用serde
和url_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,}
解决方法
通过crates.io链接到升级:https://github.com/servo/rust-url/blob/b03895bd479d72c75600dc09c8c7906f5ee203ea/UPGRADING.md
tl; dr
url = { version = "2.0",features = ["serde"] }
并删除所有对url_serde
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。