pub struct Frame<C: Ctxt> { /* private fields */ }Expand description
A set of ambient properties that are cleaned up automatically.
This type is a wrapper around a Ctxt that simplifies ambient property management. A frame containing ambient properties can be created through Frame::push or Frame::root. Those properties can be activated by calling Frame::enter. The returned EnterGuard will automatically deactivate those properties when dropped.
A frame can be converted into a future through Frame::in_future that enters and exits on each call to Future::poll so ambient properties can follow a future as it executes in an async runtime.
Implementations§
Source§impl<C: Ctxt> Frame<C>
impl<C: Ctxt> Frame<C>
Sourcepub fn push(ctxt: C, props: impl Props) -> Self
pub fn push(ctxt: C, props: impl Props) -> Self
Get a frame with the given props pushed to the current set.
Sourcepub fn disabled(ctxt: C, props: impl Props) -> Self
pub fn disabled(ctxt: C, props: impl Props) -> Self
Get a disabled frame.
The properties in props will not be visible when the frame is entered. This method should be used when props could have been pushed, but were filtered out.
Even though this frame isn’t expected to have a visible impact on the current set of ambient properties it’s still expected to be entered and exited as normal.
Sourcepub fn filtered(ctxt: C, filter: impl Fn(Str<'_>, Value<'_>) -> bool) -> Self
pub fn filtered(ctxt: C, filter: impl Fn(Str<'_>, Value<'_>) -> bool) -> Self
Get a frame with the given filter applied.
The properties visible when the frame is entered will be the current set that matches filter.
Sourcepub fn with<R>(&mut self, with: impl FnOnce(&C::Current) -> R) -> R
pub fn with<R>(&mut self, with: impl FnOnce(&C::Current) -> R) -> R
Access the properties in this frame.
Sourcepub fn enter(&mut self) -> EnterGuard<'_, C>
pub fn enter(&mut self) -> EnterGuard<'_, C>
Activate this frame.
The properties in this frame will be visible until the returned EnterGuard is dropped.
Sourcepub fn call<R>(self, scope: impl FnOnce() -> R) -> R
pub fn call<R>(self, scope: impl FnOnce() -> R) -> R
Activate this frame for the duration of scope.
The properties in this frame will be visible while scope is executing.
Sourcepub fn in_fn<R>(self, scope: impl FnOnce() -> R) -> impl FnOnce() -> R
pub fn in_fn<R>(self, scope: impl FnOnce() -> R) -> impl FnOnce() -> R
Get a FnOnce that will activate this frame when invoked.
The properties in this frame will be visible while scope is executing.
Similar to Self::call(), except that it returns a function which can be passed
to some other function, e.g.: std::thread::spawn.
Sourcepub fn in_future<F>(self, future: F) -> FrameFuture<C, F> ⓘ
pub fn in_future<F>(self, future: F) -> FrameFuture<C, F> ⓘ
Get a future that will activate this frame on each call to Future::poll.
The properties in this frame will be visible while the inner future is executing.
Sourcepub fn inner_mut(&mut self) -> &mut C::Frame
pub fn inner_mut(&mut self) -> &mut C::Frame
Get an exclusive reference to the underlying context frame.
Sourcepub const fn from_parts(ctxt: C, scope: C::Frame) -> Self
pub const fn from_parts(ctxt: C, scope: C::Frame) -> Self
Create a frame from its constituent parts.
In order to be correct, this method requires:
- That
scopewas created byctxt. - That
scopeis not currently entered.
Sourcepub fn into_parts(self) -> (C, C::Frame)
pub fn into_parts(self) -> (C, C::Frame)
Split the frame into its raw parts.
The original frame can be re-constituted by calling Frame::from_parts.