pub struct Scope { /* private fields */ }
Expand description
Request metadata, containing protocol identifier and a set of scopes, identified by type.
It works like a TypeMap with a tag. A typical way to use the scope is to match protocol
identifier by value and get one or multiple scopes.
Scope
is itself protocol-independent with protocol identifiers and scope types provided in
other crates. For example, HTTP and WebSocket are defined in servio-http crate.
ASGI equivalent: Connection Scope
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn new(protocol: Cow<'static, str>) -> Self
pub fn new(protocol: Cow<'static, str>) -> Self
Creates a new Scope
with a specified protocol identifier.
Sourcepub fn with_protocol(self, protocol: Cow<'static, str>) -> Self
pub fn with_protocol(self, protocol: Cow<'static, str>) -> Self
Returns new Scope
with specified prococol identifier, consuming surrent Scope
.
Sourcepub fn get<T: Any + Sync + Send>(&self) -> Option<Arc<T>>
pub fn get<T: Any + Sync + Send>(&self) -> Option<Arc<T>>
Returns reference-counted scope of provided type. This scope can be saved by middleware for internal use.
Sourcepub fn get_ref<T: Any + Sync + Send>(&self) -> Option<&T>
pub fn get_ref<T: Any + Sync + Send>(&self) -> Option<&T>
Returns reference to scope of provided type.
Sourcepub fn insert<T: Any + Sync + Send>(&mut self, scope: T) -> Option<Arc<T>>
pub fn insert<T: Any + Sync + Send>(&mut self, scope: T) -> Option<Arc<T>>
Inserts a scope of specified type into Scope
.
Sourcepub fn remove<T: Any + Sync + Send>(&mut self) -> Option<Arc<T>>
pub fn remove<T: Any + Sync + Send>(&mut self) -> Option<Arc<T>>
Removes a scope of specified type from Scope
.
This may be useful in middlewares, that change protocol identifier or in inter-middleware
communication.
Sourcepub fn with_scope<T: Any + Sync + Send>(self, scope: T) -> Self
pub fn with_scope<T: Any + Sync + Send>(self, scope: T) -> Self
Consumes self
and returns new Scope
with scope inserted in internal map.