不满足标准库所需类型的“默认”特征绑定

spo*_*ack 1 traits type-traits rust rust-web3

web3我正在使用板条箱中的类型,web3::contract::Contract<web3::transports::Http>. 编译器抱怨E0277

$ cargo run
   Compiling proj v0.1.0 (/home/user/proj)
error[E0277]: the trait bound `web3::contract::Contract<web3::transports::Http>: Default` is not satisfied
  --> src/book.rs:38:5
   |
38 | /     #[serde(skip)]
39 | |     abi: web3::contract::Contract<OMETransport>,
   | |_______________________________________________^ the trait `Default` is not implemented for `web3::contract::Contract<web3::transports::Http>`
   |
   = note: required by `std::default::Default::default`

error: aborting due to previous error

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

To learn more, run the command again with --verbose.
Run Code Online (Sandbox Code Playgroud)

这个错误是怎么产生的std::default::Default::default

相关类型(即包含该类型的结构体)的定义web3是:

$ cargo run
   Compiling proj v0.1.0 (/home/user/proj)
error[E0277]: the trait bound `web3::contract::Contract<web3::transports::Http>: Default` is not satisfied
  --> src/book.rs:38:5
   |
38 | /     #[serde(skip)]
39 | |     abi: web3::contract::Contract<OMETransport>,
   | |_______________________________________________^ the trait `Default` is not implemented for `web3::contract::Contract<web3::transports::Http>`
   |
   = note: required by `std::default::Default::default`

error: aborting due to previous error

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

To learn more, run the command again with --verbose.
Run Code Online (Sandbox Code Playgroud)

Ult*_*rus 5

serde文档说#[serde(skip)]

反序列化时,Serde 将使用 Default::default() 或 default = "..." 给出的函数来获取该字段的默认值。