Skip to main content

Streams

Struct Streams 

Source
pub struct Streams<T: 'static> { /* private fields */ }
Expand description

The consumers of one Emit<T> declaration’s streams, keyed by token: the stream counterpart of Registry. The generator emits one static per declaration.

Delivery rules that make a token safe to hand to a platform thread:

  • In order, one at a time. Items pushed from several threads (a response callback and a writer thread, say) reach the consumer serially, in push order. The first pusher drains the queue; the others only enqueue.
  • Re-entrancy is allowed. The consumer may stop its own stream, or cause another push to it, from inside the callback: neither waits on the callback’s lock.
  • Terminal once. After End or Failed is pushed, further pushes return false; after Streams::stop, queued items are dropped.

Implementations§

Source§

impl<T: Send + 'static> Streams<T>

Source

pub const fn new() -> Self

An empty set of streams. const, so a generated static can own it.

Source

pub fn deliver( &self, token: u64, status: i32, outcome: Result<T, Error>, ) -> bool

Deliver what a generated export received: status 0 is a value (or a failure, when the value did not convert), 2 the end, anything else a failure.

Source

pub fn emit(&self, token: u64, value: T) -> bool

Push a value. false when the stream has ended, failed, or been stopped.

Source

pub fn end(&self, token: u64) -> bool

End the stream.

Source

pub fn fail(&self, token: u64, error: Error) -> bool

Fail the stream.

Source

pub fn is_open(&self, token: u64) -> bool

Whether a consumer still listens under token.

Source

pub fn stop(&self, token: u64) -> bool

The consumer stops listening: queued items are dropped, later pushes refused, and the callback released as soon as no delivery is running.

Trait Implementations§

Source§

impl<T: Send + 'static> Default for Streams<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> !Freeze for Streams<T>

§

impl<T> Forget for Streams<T>

§

impl<T> Move for Streams<T>

§

impl<T> RefUnwindSafe for Streams<T>
where Mutex<BTreeMap<u64, Arc<StreamSlot<T>>>>: RefUnwindSafe,

§

impl<T> Send for Streams<T>
where Mutex<BTreeMap<u64, Arc<StreamSlot<T>>>>: Send,

§

impl<T> Sync for Streams<T>
where Mutex<BTreeMap<u64, Arc<StreamSlot<T>>>>: Sync,

§

impl<T> Unpin for Streams<T>
where Mutex<BTreeMap<u64, Arc<StreamSlot<T>>>>: Unpin,

§

impl<T> UnsafeUnpin for Streams<T>
where Mutex<BTreeMap<u64, Arc<StreamSlot<T>>>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Streams<T>
where Mutex<BTreeMap<u64, Arc<StreamSlot<T>>>>: UnwindSafe,

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.

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