pub struct StateFactory<T: Clone + Send + 'static> { /* private fields */ }Expand description
Factory for creating per-worker clones of shared state.
This is useful for state that needs to be cloned once per worker rather than once per request.
§Example
ⓘ
let pool = DatabasePool::new("postgres://...");
let factory = StateFactory::new(pool);
// In worker initialization
factory.init_for_worker(); // Clones pool once per worker
// In request handler - no clone needed
WorkerState::<DatabasePool>::with(|pool| {
pool.get_connection()
});Implementations§
Source§impl<T: Clone + Send + 'static> StateFactory<T>
impl<T: Clone + Send + 'static> StateFactory<T>
Sourcepub fn init_for_worker(&self)
pub fn init_for_worker(&self)
Initialize state for the current worker.
This clones the shared state once per worker.
Get a reference to the shared state.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for StateFactory<T>
impl<T> RefUnwindSafe for StateFactory<T>where
T: RefUnwindSafe,
impl<T> Send for StateFactory<T>where
T: Sync,
impl<T> Sync for StateFactory<T>where
T: Sync,
impl<T> Unpin for StateFactory<T>
impl<T> UnwindSafe for StateFactory<T>where
T: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging