std::streamStream
Streams and sinks are language intrinsics for passing typed data between producers and consumers, including across actor boundaries.
Stream<T> is a readable handle — pull items with .next() or for awaitSink<T> is a writable handle — push items with .write(value)Send (safe to pass to actors).close() is optionalimport std::stream;
fn main() {
let (sink, input) = stream.channel(16);
sink.write("hello");
sink.write("world");
sink.close(); // optional — would auto-close on drop
for await item in input {
println(item);
}
}
channelCreate a bounded in-memory channel with the given capacity.
Returns a (Sink, Stream) pair for writing and reading.
from_fileOpen a file as a readable Stream
Returns Err with the OS error message if the file cannot be opened.
let file = stream.from_file("data.txt")?;
for await line in file.lines() { println(line); }
to_fileOpen a file as a writable Sink
Returns Err with the OS error message if the file cannot be created.
let sink = stream.to_file("output.txt")?;
sink.write("hello");
// sink auto-closes when dropped
pipePipe all items from a stream into a sink, then close both.
This is the streaming equivalent of io.Copy — it reads from the source
until EOF and writes each item to the destination.
let file = stream.from_file("data.txt");
let body = req.respond_stream(200, "text/plain")?;
stream.pipe(file, body); // streams file directly to HTTP response
StreamA readable stream handle.
SinkA writable sink handle.
StreamPairInternal paired channel handle.
StreamMethodsMethods available on a Stream.
SinkMethodsMethods available on a Sink.