Skip to main content

sim_kernel/
stream.rs

1//! The [`Stream`] contract: an object that yields values until closed.
2//!
3//! This is protocol the libraries implement; the kernel defines the stream
4//! trait, not the concrete transport behind any stream.
5
6use crate::{env::Cx, error::Result, object::Object, value::Value};
7
8/// A runtime object that yields values one at a time until it is closed.
9pub trait Stream: Object {
10    /// Pulls the next value, or `Ok(None)` once the stream is exhausted.
11    fn next(&self, cx: &mut Cx) -> Result<Option<Value>>;
12
13    /// Releases any resources backing the stream; idempotent by default.
14    fn close(&self, _cx: &mut Cx) -> Result<()> {
15        Ok(())
16    }
17}