Skip to main content

CallbackSlot

Struct CallbackSlot 

Source
pub struct CallbackSlot<T: 'static> { /* private fields */ }
Available on crate feature embedded_runtime only.
Expand description

An address-stable slot holding a caller-provided callback for the duration of a run, backing an output (or network-out) parameter of a generated embedded function.

The flow side holds a sink closure (created via sink) that forwards each emitted item to whatever callback is currently installed. The application side temporarily installs a callback around each run via invoke_with:

slot.invoke_with(&mut |item| results.push(item), || flow.run_available_sync());

Items emitted while no callback is installed are silently dropped.

Implementations§

Source§

impl<T: 'static> CallbackSlot<T>

Source

pub const fn new() -> Self

Creates a slot with no callback installed.

Source

pub unsafe fn sink(self: Pin<&Self>) -> impl FnMut(T) + use<T>

Creates a sink closure that forwards each item to the currently-installed callback, for passing to a generated embedded function.

§Safety

The slot must outlive the returned closure. (The slot cannot move while the closure exists, which is guaranteed by self being pinned, and the closure cannot be sent to another thread, as it is !Send.)

Source

pub fn invoke(&self, item: T)

Invokes the currently-installed callback with item, or drops item if no callback is installed.

The callback is moved out of the slot while it runs (and restored afterwards, even on panic), so a re-entrant invocation of the same slot finds it empty and drops its item, rather than aliasing the already-running callback.

Source

pub fn invoke_with<R>( &self, callback: &mut dyn FnMut(T), f: impl FnOnce() -> R, ) -> R

Installs callback for the duration of f, then restores whatever was previously installed — even if f panics. Items the flow emits to this slot while f runs are passed to callback.

Calls may be nested (e.g. to install callbacks on several slots around a single run); the innermost installation wins for its duration.

Trait Implementations§

Source§

impl<T: 'static> Debug for CallbackSlot<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: 'static> Default for CallbackSlot<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for CallbackSlot<T>

§

impl<T> !RefUnwindSafe for CallbackSlot<T>

§

impl<T> !Send for CallbackSlot<T>

§

impl<T> !Sync for CallbackSlot<T>

§

impl<T> !Unpin for CallbackSlot<T>

§

impl<T> !UnsafeUnpin for CallbackSlot<T>

§

impl<T> !UnwindSafe for CallbackSlot<T>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToSinkBuild for T

Source§

fn iter_to_sink_build(self) -> SendIterBuild<Self>
where Self: Sized + Iterator,

Starts a SinkBuild adaptor chain to send all items from self as an Iterator.
Source§

fn stream_to_sink_build(self) -> SendStreamBuild<Self>
where Self: Sized + Stream,

Starts a SinkBuild adaptor chain to send all items from self as a [Stream].
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more