pub struct DependencyOverrides { /* private fields */ }Expand description
Dependency override registry (primarily for testing).
Implementations§
Source§impl DependencyOverrides
impl DependencyOverrides
Sourcepub fn insert<T, F, Fut>(&self, f: F)where
T: FromDependency,
F: Fn(&RequestContext, &mut Request) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<T, T::Error>> + Send + 'static,
pub fn insert<T, F, Fut>(&self, f: F)where
T: FromDependency,
F: Fn(&RequestContext, &mut Request) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<T, T::Error>> + Send + 'static,
Register an override resolver for a dependency type.
Sourcepub fn insert_value<T>(&self, value: T)where
T: FromDependency,
pub fn insert_value<T>(&self, value: T)where
T: FromDependency,
Register a fixed override value for a dependency type.
Sourcepub async fn resolve<T>(
&self,
ctx: &RequestContext,
req: &mut Request,
) -> Option<Result<T, T::Error>>where
T: FromDependency,
pub async fn resolve<T>(
&self,
ctx: &RequestContext,
req: &mut Request,
) -> Option<Result<T, T::Error>>where
T: FromDependency,
Resolve an override if one exists for T.
§Type Safety
The override is looked up by TypeId::of::<T>(), which should guarantee
that the stored closure returns the correct types. If a type mismatch
occurs despite the TypeId matching:
- In debug builds: panics via
debug_assert!to catch bugs early - In release builds: returns
Noneto fall back to normal resolution
Trait Implementations§
Source§impl Debug for DependencyOverrides
impl Debug for DependencyOverrides
Auto Trait Implementations§
impl !Freeze for DependencyOverrides
impl !RefUnwindSafe for DependencyOverrides
impl Send for DependencyOverrides
impl Sync for DependencyOverrides
impl Unpin for DependencyOverrides
impl !UnwindSafe for DependencyOverrides
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).