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 send_email(email: String, state: Data<Arc<State>>) {
}
let state = Arc::new(State { /* ... */ });
let backend = MemoryStorage::new();
let worker = WorkerBuilder::new("tasty-avocado")
.backend(backend)
.data(state)
.build(send_email);Implementations§
Trait Implementations§
Source§impl<T: Clone + Send + Sync + 'static, Args: Sync, Ctx: Sync, IdType: Sync + Send> FromRequest<Task<Args, Ctx, IdType>> for Data<T>
impl<T: Clone + Send + Sync + 'static, Args: Sync, Ctx: Sync, IdType: Sync + Send> FromRequest<Task<Args, Ctx, IdType>> for Data<T>
Source§type Error = MissingDataError
type Error = MissingDataError
The error type that can occur during extraction.
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