# Daniel/Eric ## 2023-02-16 Latest on async in trait Send bounds ```rust= trait async HealthCheck { async fn check(&mut self, server: Server); } fn do_health_check<H>(health_check: H, server: Server) where H: async(Send) HealthCheck { } ``` Semver trap ```rust= fn do_health_check<H>(health_check: H, server: Server) where H: HealthCheck + infer Send, { } ``` ```rust // Is foo() Send? depends on the body async(Send) fn foo() { } async fn foo() where return: Send { } ``` ## 2023-02-09 ```rust use std::cell::RefCell; struct Foo<'a> { quux: usize, bar: RefCell<Option<&'a usize>>, } fn baz<'a>(x: &'a Foo<'a>) -> &'a usize { *x.bar.borrow_mut() = Some(&x.quux); &x.quux } fn main() { let x = Foo { quux: 42, bar: RefCell::new(None) }; // Why does this work? baz(&x); // this works println!("{:?}", x.quux); // this doesn't let x = Box::new(x); println!("{:?}", x.bar); } ``` ```rust struct Foo<'a> { quux: usize, bar: Option<&'a usize>, } fn baz<'a>(x: &'a mut Foo<'a>) -> &'a usize { x.bar = Some(&x.quux); &x.quux } fn main() { let mut x = Foo { quux: 42, bar: None }; // Why does this work? baz(&mut x); // These lines make it not work, because we are trying // to move out of x while x is borrowed. // // let x = Box::new(x); // println!("{:?}", x.bar); } ``` ```rust struct Foo<'a> { quux: usize, bar: &'a usize, } fn baz<'a>(x: &'a mut Foo<'a>) -> &'a usize { x.bar = &x.quux; &x.quux } ``` ## 2023-01-20 ```rust= trait Foo { async<Send + Sync> fn foo() -> usize; // fn foo() -> impl Future<Output = usize> + Send + Sync #[async_send] async fn bar(); async fn baz(x: impl AsyncFn()) where async: Send; } async fn<T: Foo<foo(): Send>> quux(t: T) { } impl Debug for <usize as Foo>::foo() { } ``` ## Last week ```rust= trait MyTrait { // async fn foo(&self) -> usize; fn foo(&self) -> impl Future<Output = usize> + '_; } async fn use_dyn_trait( // you write: bar: &dyn MyTrait, // the compiler interprets that as: // // bar: &dyn MyTrait<foo() = dyn* Future<Output = usize> + '_>) { bar.foo().await; } async call_use_dyn_trait() { let bar = some_my_trait_impl(); let arena = Arena::new(); use_dyn_trait(&bar.into_dyn()).await; } trait IntoDyn<trait DynTrait> { fn into_dyn(self) -> ??? } #[derive(IntoDyn<MyTrait>)] struct MyThing { } impl<T: MyTrait> IntoDyn for T { } ```