pub struct CxBuilder { /* private fields */ }Expand description
Assembles the request context for an in-flight request.
The router creates a CxBuilder over the shared app context, then threads
&mut CxBuilder through the layers wrapping the matched route so each can
register request-scoped values with insert before the
route runs. Because a CxBuilder dereferences to the Cx it is building,
app and request context can be read through it (with app_context and
request_context) while it is still being assembled.
Implementations§
Source§impl CxBuilder
impl CxBuilder
Sourcepub fn new(app_context: Arc<ContextMap>) -> Self
pub fn new(app_context: Arc<ContextMap>) -> Self
Creates a builder over the shared app context, with an empty request context.
Sourcepub fn insert<T>(&mut self, value: T) -> Option<T>
pub fn insert<T>(&mut self, value: T) -> Option<T>
Registers value on the request context, returning the value previously
registered for T, if any.
A type can hold only one value at a time, so registering a type that is already present replaces it and hands back the displaced value.
Sourcepub fn contains<T>(&self) -> bool
pub fn contains<T>(&self) -> bool
Returns true if a value of type T has been registered on the request
context.
Sourcepub fn get<T>(&self) -> Option<&T>
pub fn get<T>(&self) -> Option<&T>
Returns a reference to the request context value of type T, or None
if no such value has been registered.