fn assert_is_send(_: &T) {} fn assert_is_sync(_: &T) {} mod borrow_dyn_sync { use super::*; use entrait::*; #[entrait(Foo)] fn foo(deps: &impl Bar) { deps.bar(); } #[entrait(delegate_by=ref)] trait Bar: 'static { fn bar(&self); } struct App(Box); impl AsRef for App { fn as_ref(&self) -> &dyn Bar { self.0.as_ref() } } struct Baz; impl Bar for Baz { fn bar(&self) {} } #[test] fn test_impl_borrow() { let app = Impl::new(App(Box::new(Baz))); assert_is_sync(&app); app.foo(); } } mod borrow_dyn_with_async_trait { use super::*; use async_trait::*; use entrait::*; #[entrait(Foo)] async fn foo(deps: &impl Bar) { deps.bar().await; } #[entrait(delegate_by=ref)] #[async_trait] trait Bar: Sync + 'static { async fn bar(&self); } struct Baz; struct App(Baz); impl AsRef for App { fn as_ref(&self) -> &dyn Bar { &self.0 } } #[async_trait] impl Bar for Baz { async fn bar(&self) {} } #[tokio::test] async fn test_async_borrow() { let app = Impl::new(App(Baz)); assert_is_send(&app); assert_is_sync(&app); app.foo().await; } }