pub struct Data<T>(/* private fields */);
Expand description
Extension data for tasks. This is commonly used to share state across tasks. or across layers within the same tasks
// Some shared state used throughout our application
struct State {
// ...
}
async fn email_service(email: Email, state: Data<Arc<State>>) {
}
let state = Arc::new(State { /* ... */ });
let worker = WorkerBuilder::new("tasty-avocado")
.data(state)
.backend(MemoryStorage::new())
.build(service_fn(email_service));
Implementations§
Trait Implementations§
impl<T: Copy> Copy for Data<T>
Auto Trait Implementations§
impl<T> Freeze for Data<T>where
T: Freeze,
impl<T> RefUnwindSafe for Data<T>where
T: RefUnwindSafe,
impl<T> Send for Data<T>where
T: Send,
impl<T> Sync for Data<T>where
T: Sync,
impl<T> Unpin for Data<T>where
T: Unpin,
impl<T> UnwindSafe for Data<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more