std::streamStream
Streams and sinks are language intrinsics for passing typed data between producers and consumers, including across actor boundaries.
Contract slice frozen here:
Stream<bytes> / Sink<bytes> are the canonical first-class foundationStream<string> / Sink<string> are convenience text ABI wrappersbytes and empty string
values are valid itemssink.close() or drop yields graceful EOF; stream.close() or drop is a
local cancel/discard of unread items.recv() / .write() operations are blocking and backpressured; no
nonblocking semantics are promised hereCurrent stdlib scope:
bytes_pipe() is the canonical in-memory constructorpipe() remains the text convenience constructorfrom_file() / to_file() remain Stream<string> / Sink<string>lines() remains a Stream<string> adapter todayimport std::stream;
fn main() {
let (sink, input) = stream.pipe(16);
sink.write("hello");
sink.write("world");
sink.close(); // optional — would auto-close on drop
for await item in input {
println(item);
}
}
pipeCreate a bounded in-memory string pipe with the given capacity.
This is the convenience text ABI lane over the same bounded, blocking,
backpressured contract as bytes_pipe().
Returns a (Sink<string>, Stream<string>) pair for writing and reading.
bytes_pipeCreate a bounded in-memory bytes pipe with the given capacity.
This is the canonical first-class Stream/Sink foundation for binary items.
Returns a (Sink<bytes>, Stream<bytes>) 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.
This stage only freezes constructor/open errors; read-time failures after a
stream is opened remain wrapper-specific and out of scope for the core
Stream/Sink contract.
Prefer try_from_file for a structured Result<Stream<string>, fs.IoError>.
Import std::fs as well if you want to match on IoError variants.
let file = stream.from_file("data.txt")?;
for await line in file.lines() { println(line); }
try_from_fileOpen a file as a readable Stream<string>.
This preserves from_file's runtime behaviour while returning fs.IoError
instead of a raw OS message string. Import std::fs when matching on the
returned error value so you can use the existing unqualified
IoError::Variant(...) constructor/pattern style.
to_fileOpen a file as a writable Sink
Returns Err with the OS error message if the file cannot be created.
This stage only freezes constructor/open errors; write-time failures after a
sink is opened remain wrapper-specific and out of scope for the core
Stream/Sink contract.
Prefer try_to_file for a structured Result<Sink<string>, fs.IoError>.
Import std::fs as well if you want to match on IoError variants.
let sink = stream.to_file("output.txt")?;
sink.write("hello");
// sink auto-closes when dropped
try_to_fileOpen a file as a writable Sink<string>.
This preserves to_file's runtime behaviour while returning fs.IoError
instead of a raw OS message string. Import std::fs when matching on the
returned error value so you can use the existing unqualified
IoError::Variant(...) constructor/pattern style.
forwardPipe 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.forward(file, body); // streams file directly to HTTP response
StreamPairInternal paired channel handle.