Skip to main content

Frame

Struct Frame 

Source
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>

Source

pub fn current(ctxt: C) -> Self

Get a frame with the current set of ambient properties.

Source

pub fn push(ctxt: C, props: impl Props) -> Self

Get a frame with the given props pushed to the current set.

Source

pub fn root(ctxt: C, props: impl Props) -> Self

Get a frame for just the properties in props.

Source

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.

Source

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.

Source

pub fn with<R>(&mut self, with: impl FnOnce(&C::Current) -> R) -> R

Access the properties in this frame.

Source

pub fn enter(&mut self) -> EnterGuard<'_, C>

Activate this frame.

The properties in this frame will be visible until the returned EnterGuard is dropped.

Source

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.

Source

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.

Source

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.

Source

pub fn inner(&self) -> &C::Frame

Get a reference to the underlying context frame.

Source

pub fn inner_mut(&mut self) -> &mut C::Frame

Get an exclusive reference to the underlying context frame.

Source

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:

  1. That scope was created by ctxt.
  2. That scope is not currently entered.
Source

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.

Trait Implementations§

Source§

impl<C: Ctxt> Drop for Frame<C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<C> Freeze for Frame<C>

§

impl<C> RefUnwindSafe for Frame<C>

§

impl<C> Send for Frame<C>

§

impl<C> Sync for Frame<C>

§

impl<C> Unpin for Frame<C>

§

impl<C> UnsafeUnpin for Frame<C>

§

impl<C> UnwindSafe for Frame<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.