pub struct CallbackSlot<T: 'static> { /* private fields */ }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>
impl<T: 'static> CallbackSlot<T>
Sourcepub unsafe fn sink(self: Pin<&Self>) -> impl FnMut(T) + use<T>
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.)
Sourcepub fn invoke(&self, item: T)
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.
Sourcepub fn invoke_with<R>(
&self,
callback: &mut dyn FnMut(T),
f: impl FnOnce() -> R,
) -> R
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>
impl<T: 'static> Debug for CallbackSlot<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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