pub struct Stream<S>(/* private fields */);Expand description
A wrapper around futures::Stream implementing Source trait.
Stream items must implement Message.
Implementations§
Source§impl<S> Stream<S>
impl<S> Stream<S>
Sourcepub fn new(stream: S) -> Self
pub fn new(stream: S) -> Self
Wraps futures::Stream into the source.
Sourcepub fn replace(&self, stream: S) -> Option<S>where
S: Unpin,
pub fn replace(&self, stream: S) -> Option<S>where
S: Unpin,
Replaces the inner stream with the provided one.
Sourcepub fn close(&self) -> bool
pub fn close(&self) -> bool
Drops the inner stream and stops emitting messages.
Stream::set and Stream::replace can be used after this method.
Source§impl Stream<()>
impl Stream<()>
Sourcepub fn generate<G, F>(generator: G) -> Stream<impl Stream<Item = Envelope>>
pub fn generate<G, F>(generator: G) -> Stream<impl Stream<Item = Envelope>>
Generates a stream from the provided generator.
The generator receives Yielder as an argument and should return a
future that will produce messages by using Yielder::emit.
§Examples
ⓘ
#[message]
struct SomeMessage(u32);
#[message]
struct AnotherMessage;
let stream = Stream::generate(|mut y| async move {
y.emit(SomeMessage(42)).await;
y.emit(AnotherMessage).await;
});
let mut ctx = ctx.with(&stream);Auto Trait Implementations§
impl<S> !Freeze for Stream<S>
impl<S> !RefUnwindSafe for Stream<S>
impl<S> Send for Stream<S>where
S: Send,
impl<S> Sync for Stream<S>where
S: Send,
impl<S> Unpin for Stream<S>
impl<S> UnwindSafe for Stream<S>where
S: UnwindSafe,
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
Mutably borrows from an owned value. Read more