我有以下 rust 代码,对于我的生活,我无法解决为什么我会遇到与此值有关的借用检查器问题,以及为什么它会作为 while 循环的一部分被移动。
代码:
#[tokio::main]
async fn main() -> Fallible<()> {
let config = Config::new().expect("config can't be loaded");
logger::config(&config.log);
let bn = Binance::with_credential(
&config.exchanges.binance_com.api_key,
&config.exchanges.binance_com.api_secret,
);
let mut db = Database::new(config).await;
match bn.user_stream_start()?.await {
Ok(_) => {
let mut ws = BinanceWebsocket::default();
for sub in vec![Subscription::Trade("btcusdt".to_string())] {
ws.subscribe(sub).await?;
}
while let Some(msg) = ws.try_next().await? {
db.write(msg).await?
}
}
Err(e) => error!("Error obtaining stream: {}", e),
};
Ok(())
}
错误:
error[E0382]: use of moved value: `db`
--> x/src/main.rs:35:17
|
24 | let mut db = Database::new(config).await;
| ------ move occurs because `db` has type `Database`, which does not implement the `Copy` trait
...
35 | db.write(msg).await?
| ^^ value moved here, in previous iteration of loop
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0382`.
非常感谢任何帮助