Skip to main content

StreamValue

Struct StreamValue 

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

The runtime-visible stream value: metadata plus a live spine.

A StreamValue is the homogeneous stream object the runtime passes around. It is a non-citizen live handle (it is not serialized directly; consumers reconstruct the stream/Packet and stream/Metadata descriptors and realize them separately). Build a finite, replayable stream with StreamValue::pull or a producer-fed stream with StreamValue::push, then drive it through the base combinators (next_packet, peek_packet, take_packets, run_events, cancel, is_done).

As a kernel Object it presents as a Sequence, so it interoperates with sequence-consuming operations directly.

Implementations§

Source§

impl StreamValue

Source

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

Builds a pull stream that yields the given pre-built items in order.

A pull stream is finite and self-draining: it serves items until exhausted, then reports done. It rejects pushed packets.

Source

pub fn push(metadata: StreamMetadata) -> Self

Builds a push stream fed by an external producer.

The stream starts empty; producers call StreamValue::push_packet to enqueue items under the buffer policy carried by metadata, and consumers pull them out.

Source

pub fn metadata(&self) -> &StreamMetadata

Returns the stream’s immutable metadata.

Source

pub fn publish_claims(&self, cx: &mut Cx, subject: Ref) -> Result<()>

Publishes this stream’s metadata as claims about subject into cx.

Source

pub fn push_packet(&self, item: StreamItem) -> Result<PushResult>

Pushes a packet into a push stream, returning the backpressure outcome.

Returns an error when called on a pull stream, which accepts no input.

Source

pub fn close_push(&self) -> Result<()>

Closes the stream to further input, leaving buffered items to drain.

Source

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

Pulls the next packet, or None if the stream is currently empty or exhausted.

Does not block; on a push stream an empty-but-open queue yields None.

Source

pub fn next_packet_timeout( &self, timeout: Duration, ) -> Result<Option<StreamItem>>

Pulls the next packet, blocking up to timeout for one to arrive.

On a pull stream this is equivalent to StreamValue::next_packet; on a push stream it waits for a producer up to timeout before yielding None.

Source

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

Returns a clone of the next packet without consuming it.

Source

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

Reports whether the stream is exhausted and will yield no more packets.

Source

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

Pulls up to limit packets, stopping early when the stream runs dry.

Source

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

Drains the stream into a vector of sequenced packet events.

Pulls every currently available packet, emitting one packet Event per item numbered from start_seq, and appends a terminal done event if the stream is exhausted. Events are attributed to run.

Source

pub fn cancel(&self) -> Result<()>

Cancels the stream: closes it and discards any buffered packets.

Source

pub fn stats(&self) -> Result<StreamStats>

Returns a snapshot of the stream’s lifetime StreamStats.

Source

pub fn queue_depth(&self) -> Result<usize>

Returns the number of packets currently buffered in the spine.

Source

pub fn event_source( self: &Arc<Self>, run: Ref, start_seq: u64, ) -> Arc<StreamEventSource>

Builds an StreamEventSource that feeds this stream’s packets into the run ledger as sequenced events numbered from start_seq.

Trait Implementations§

Source§

impl Object for StreamValue

Source§

fn display(&self, _cx: &mut Cx) -> Result<String>

Render the object as a human-readable display string.
Source§

fn as_any(&self) -> &dyn Any

Expose the object for Rust downcasting.
Source§

fn header(&self) -> &ObjectHeader

Identity and trust header for the object; defaults to the shared anonymous header.
Source§

fn op(&self, _key: &OpKey) -> Option<&dyn Op>

Resolve the operation registered under key, if any.
Source§

fn claims( &self, _cx: &mut Cx, _pattern: &ClaimPattern, _sink: &mut dyn ClaimSink, ) -> Result<(), Error>

Emit the object’s claims matching pattern into sink.
Source§

fn snapshot(&self, _cx: &mut Cx) -> Result<Option<Datum>, Error>

Optional content-addressable snapshot of the object’s state.
Source§

impl ObjectCompat for StreamValue

Source§

fn class(&self, cx: &mut Cx) -> Result<ClassRef>

Class object this value belongs to; defaults to nil.
Source§

fn as_sequence(&self) -> Option<&dyn Sequence>

Sequence view, if the object is a sequence.
Source§

fn as_callable(&self) -> Option<&dyn Callable>

Callable view, if the object can be invoked.
Source§

fn as_class(&self) -> Option<&dyn Class>

Class view, if the object is a class.
Source§

fn as_shape(&self) -> Option<&dyn Shape>

Shape view, if the object is a shape.
Source§

fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>

Object-encoder view, if the object encodes other objects.
Source§

fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>

Read-constructor view, if the object decodes data forms.
Source§

fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>

Number-domain view, if the object is a number domain.
Source§

fn as_number_value(&self) -> Option<&dyn NumberValue>

Number-value view, if the object is a domain number.
Source§

fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>

Eval-fabric view, if the object is a distributed eval surface.
Source§

fn as_stream(&self) -> Option<&dyn Stream>

Stream view, if the object is a stream.
Source§

fn as_thunk(&self) -> Option<&dyn Thunk>

Thunk view, if the object is a deferred computation.
Source§

fn as_list(&self) -> Option<&(dyn ListValue + 'static)>

List view, if the object is a list value.
Source§

fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>

Table-implementation view, if the object is a table.
Source§

fn as_dir(&self) -> Option<&(dyn Dir + 'static)>

Directory view, if the object is a directory.
Source§

fn as_expr(&self, cx: &mut Cx) -> Result<Expr, Error>

Expression form of the object; defaults to an opaque extension node.
Source§

fn truth(&self, _cx: &mut Cx) -> Result<bool, Error>

Truthiness of the object; defaults to true.
Source§

fn publish_shape_satisfaction_claims( &self, _cx: &mut Cx, _shape: &Ref, ) -> Result<bool, Error>

Publish claims asserting that the object satisfies shape; returns whether any were published.
Source§

fn as_table(&self, cx: &mut Cx) -> Result<Value, Error>

Project the object into a table value; the default exposes its display.
Source§

impl Sequence for StreamValue

Source§

fn next_item(&self, cx: &mut Cx) -> Result<Option<SequenceItem>>

Pulls the next item, or Ok(None) once exhausted.
Source§

fn close(&self, _cx: &mut Cx) -> Result<()>

Releases resources backing the sequence; idempotent by default.
Source§

fn peek_item(&self, cx: &mut Cx) -> Result<Option<SequenceItem>>

Peeks the next item without consuming it; unsupported by default.
Source§

fn is_done(&self, _cx: &mut Cx) -> Result<bool>

Whether the sequence is known to be exhausted; false by default.

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> 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> RuntimeObject for T
where T: Object + ObjectCompat + Any + Send + Sync,

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.