我有一个 Rust 应用程序,使用warp. 它实现了 RESTful CRUD API。我需要每个路由处理程序(即最终由扭曲过滤器调用的函数)能够访问并(在大多数情况下)改变共享应用程序状态。
我可以编译它的唯一方法是Arc<Mutex<State>> 为每个路由克隆一个:
/* internal_state is loaded from a dump file earlier on and is of type `State` */
let state: Arc<Mutex<State>> = Arc::new(Mutex::new(internal_state));
let index_book_state: Arc<Mutex<State>> = state.clone();
let create_book_state: Arc<Mutex<State>> = state.clone();
let read_book_state: Arc<Mutex<State>> = state.clone();
let create_order_state: Arc<Mutex<State>> = state.clone();
let read_order_state: Arc<Mutex<State>> = state.clone();
let update_order_state: Arc<Mutex<State>> = state.clone();
let destroy_order_state: Arc<Mutex<State>> = state.clone();
/* define CRUD routes for order books */
let book_prefix = …Run Code Online (Sandbox Code Playgroud) 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 …Run Code Online (Sandbox Code Playgroud)