gpt4 book ai didi

rust - 不满足 `Default` 特征绑定(bind)在标准库所需的类型上

转载 作者:行者123 更新时间:2023-12-03 11:41:29 24 4
gpt4 key购买 nike

我正在使用 web3 crate 中的类型, 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.
这个错误怎么可能来自 std::default::Default::default ?
相关类型(即包含 web3 类型的结构)的定义是:
/// 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>,
}

最佳答案

serde documentation对于 #[serde(skip)]说:

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

关于rust - 不满足 `Default` 特征绑定(bind)在标准库所需的类型上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65930855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com