KR
Size: a a a
KR
Ct
mem::take вынимать. Если у нас enum с референсом на себя в одном варианте, который не совпадает с Default, то этот референс будет указывать на неинициализированную память после мува.Ct
PL
Option<...> иметь вне цикла, что мало чем от Fuse<...> отличается. Даже если решить проблемы с selfrefRG
С
YM
tokio правильно таймаут образовать для TcpStream::connect,tokio::time::delay_for ??YM
tokio::time::timeout`RG
A
use std::{
sync::Arc,
convert::Infallible,
};
use tokio::sync::Mutex;
use warp::Filter;
type Ctl = Arc<Mutex<Control>>;
struct Control {
foo: bool,
// bar: Option<Box<dyn Bar>>,
}
trait Bar {}
#[tokio::main]
async fn main() {
let ctl = Arc::new(Mutex::new(Control {
foo: true,
// bar: None,
}));
let ctl = warp::any().map(move || ctl.clone());
let routes = warp::any()
.and(ctl)
.and_then(dump_ctl);
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}
async fn dump_ctl(ctl: Ctl) -> Result<impl warp::Reply, Infallible> {
Ok(format!("ctl.foo = {}", ctl.lock().await.foo))
}В
use std::{
sync::Arc,
convert::Infallible,
};
use tokio::sync::Mutex;
use warp::Filter;
type Ctl = Arc<Mutex<Control>>;
struct Control {
foo: bool,
// bar: Option<Box<dyn Bar>>,
}
trait Bar {}
#[tokio::main]
async fn main() {
let ctl = Arc::new(Mutex::new(Control {
foo: true,
// bar: None,
}));
let ctl = warp::any().map(move || ctl.clone());
let routes = warp::any()
.and(ctl)
.and_then(dump_ctl);
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}
async fn dump_ctl(ctl: Ctl) -> Result<impl warp::Reply, Infallible> {
Ok(format!("ctl.foo = {}", ctl.lock().await.foo))
}В
+ Send + SyncA
+ Send + SyncA
Ct
#[tokio::main] ошибку портит.A
#[tokio::main] ошибку портит.A
В
A
