V
Size: a a a
V
d
d
YM
YM
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))
}A
pub struct SendPtr<T> {
pub ptr: *mut T
}
unsafe impl<T> Send for SendPtr<T> {}YM
BM
BM
YM
BM
BM
BM
BM
В
try_fold определён в TryStreamExt?try_fold'ить обычный стрим?В
while let + .next, но это как-то совсем некрасивоD