1

I'm using a type from the web3 crate, web3::contract::Contract<web3::transports::Http>. The compiler is complaining with 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.

How can this error originate from std::default::Default::default?

The definition for the relevant type (i.e., the struct containing the web3 type) is:

/// Represents an order book for a particular market
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Book {
    market: Address, /* the address of the market */
    bids: BTreeMap<U256, VecDeque<Order>>, /* buy-side */
    asks: BTreeMap<U256, VecDeque<Order>>, /* sell-side */
    #[serde(serialize_with = "from_hex_se", deserialize_with = "from_hex_de")]
    ltp: U256, /* last traded price */
    depth: (usize, usize), /* depth  */
    crossed: bool,   /* is book crossed? */
    #[serde(serialize_with = "from_hex_se", deserialize_with = "from_hex_de")]
    spread: U256, /* bid-ask spread */
    #[serde(skip)]
    abi: web3::contract::Contract<web3::transports:Http>,
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
sporejack
  • 71
  • 1
  • 6

1 Answers1

5

the serde documentation for #[serde(skip)] says:

When deserializing, Serde will use Default::default() or the function given by default = "..." to get a default value for this field.

Ultrasaurus
  • 3,031
  • 2
  • 33
  • 52