pub struct Snapshot { /* private fields */ }Expand description
What one request may read: one Arc per section, taken together.
Built by Sections::take when the request begins, and read by an
adapter’s extractor. Two reads of the same section answer the same
Arc, however far apart in the handler they are and whatever lands in
between.
Implementations§
Source§impl Snapshot
impl Snapshot
Sourcepub fn get<T>(&self) -> Option<Arc<T>>
pub fn get<T>(&self) -> Option<Arc<T>>
The section of type T this request began with.
None when T was not among the sections, or was among them and
had not loaded yet. require tells those apart.
Sourcepub fn require<T>(&self) -> Result<Arc<T>, NotInScope>
pub fn require<T>(&self) -> Result<Arc<T>, NotInScope>
The section of type T, or why it is not here.
§Errors
NotInScope::NotListed when T was never registered — a wiring
mistake, fixed where the layer is built. NotInScope::NotLoaded
when it was registered and nothing has installed a value yet — a
startup-order mistake, fixed by loading before serving. The two have
different fixes, which is why they are different variants.
Sourcepub fn names(&self) -> Vec<&'static str>
pub fn names(&self) -> Vec<&'static str>
The type names registered, whether or not each had loaded.
Sourcepub fn merged_with(self, inner: Snapshot) -> Snapshot
pub fn merged_with(self, inner: Snapshot) -> Snapshot
This snapshot with inner’s sections laid over it.
What an adapter uses when layers nest and each carries its own list. The inner one wins where both registered a type, because it is the more specific of the two — and nothing is lost, which is the point: a handler under both layers can read either’s sections.