Skip to main content

Stream

Struct Stream 

Source
pub struct Stream { /* private fields */ }
Expand description

Cloneable handle to a lazy combinator stream.

A Stream is a thin shared pointer over a StreamNode: cloning it shares the same underlying source rather than copying packets. It is the value that every combinator in this crate consumes and produces, forming pull-based graphs over the homogeneous sim-stream packet spine.

§Examples

use sim_kernel::{Expr, Symbol};
use sim_lib_stream_core::{
    BufferOverflowPolicy, BufferPolicy, StreamDirection, StreamItem, StreamMedia,
    StreamMetadata, StreamPacket,
};
use sim_lib_stream_combinators::Stream;

let metadata = StreamMetadata::new(
    Symbol::qualified("stream", "doc"),
    StreamMedia::Data,
    StreamDirection::Source,
    Symbol::qualified("clock", "doc"),
    BufferPolicy::bounded_with_overflow(8, BufferOverflowPolicy::DropNewest).unwrap(),
);
let item = StreamItem::new(StreamPacket::data(
    Symbol::qualified("stream/data", "model-event"),
    Expr::Nil,
));
let stream = Stream::pull(metadata, vec![item.clone()]);
assert_eq!(stream.take_packets(8).unwrap(), vec![item]);
assert!(stream.is_done().unwrap());

Implementations§

Source§

impl Stream

Source

pub fn new(inner: impl StreamNode + 'static) -> Self

Wraps a StreamNode implementation in a shareable Stream handle.

Source

pub fn from_value(value: Arc<StreamValue>) -> Self

Builds a stream that replays the packets held by a stream-core value.

Source

pub fn pull(metadata: StreamMetadata, items: Vec<StreamItem>) -> Self

Builds an in-memory pull stream from explicit metadata and packets.

Source

pub fn metadata(&self) -> &StreamMetadata

Returns the metadata describing this stream’s media, clock, and buffer.

Source

pub fn next_packet(&self) -> Result<Option<StreamItem>>

Pulls the next packet, or Ok(None) when none is currently available.

Source

pub fn is_done(&self) -> Result<bool>

Reports whether the stream has reached its terminal done state.

Source

pub fn take_packets(&self, limit: usize) -> Result<Vec<StreamItem>>

Pulls up to limit packets, stopping early when the source is drained.

Source

pub fn run_events( &self, cx: &mut Cx, run: Ref, start_seq: u64, ) -> Result<Vec<Event>>

Drains the stream into kernel events, one chunk event per packet.

Sequence numbers start at start_seq and increase per packet; a final done event for run is appended once the source reports done.

Source

pub fn map_data_expr<F>(self, f: F) -> Self
where F: Fn(Expr) -> Result<Expr> + Send + Sync + 'static,

Returns a stream that rewrites each data packet’s payload expression.

Method form of the free map_data_expr combinator; non-data packets pass through unchanged.

Source

pub fn filter_data_kind(self, kind: Symbol) -> Self

Returns a stream keeping only data packets of the given kind.

Method form of the free filter_data_kind combinator.

Source

pub fn filter_data_shape<F>(self, matches: F) -> Self
where F: Fn(&Expr) -> Result<bool> + Send + Sync + 'static,

Returns a stream keeping data packets whose payload matches matches.

Method form of the free filter_data_shape combinator.

Source

pub fn window_by_count(self, count: usize) -> Self

Returns a stream that batches packets into windows of count packets.

Method form of the free window_by_count combinator.

Source

pub fn tap_diagnostics<F>(self, f: F) -> Self
where F: Fn(&StreamDiagnostic) -> Result<()> + Send + Sync + 'static,

Returns a stream that observes each diagnostic packet without altering it.

Method form of the free tap_diagnostics combinator.

Trait Implementations§

Source§

impl Clone for Stream

Source§

fn clone(&self) -> Stream

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.