| Crates.io | moosicbox_stream_utils |
| lib.rs | moosicbox_stream_utils |
| version | 0.1.4 |
| created_at | 2024-10-04 02:48:03.756616+00 |
| updated_at | 2025-07-21 19:15:39.585239+00 |
| description | MoosicBox stream utils package |
| homepage | |
| repository | https://github.com/MoosicBox/MoosicBox |
| max_upload_size | |
| id | 1395985 |
| size | 100,846 |
Basic byte stream utilities for simple data streaming in the MoosicBox ecosystem.
The MoosicBox Stream Utils package provides:
stalled-monitor feature)remote-bytestream feature)[dependencies]
moosicbox_stream_utils = { path = "../stream_utils" }
# Optional: Enable specific features
moosicbox_stream_utils = {
path = "../stream_utils",
features = ["stalled-monitor", "remote-bytestream"]
}
use moosicbox_stream_utils::{ByteWriter, ByteStream};
use std::io::Write;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a byte writer
let mut writer = ByteWriter::default();
// Create streams from the writer
let stream1 = writer.stream();
let stream2 = writer.stream();
// Write data to the writer
writer.write_all(b"Hello, world!")?;
writer.close();
// Read from the streams
let data1: Vec<_> = stream1.collect().await;
let data2: Vec<_> = stream2.collect().await;
println!("Stream 1 received {} chunks", data1.len());
println!("Stream 2 received {} chunks", data2.len());
Ok(())
}
use moosicbox_stream_utils::{TypedWriter, TypedStream};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a typed writer for strings
let writer = TypedWriter::<String>::default();
let mut stream = writer.stream();
// Write some data
writer.write("Hello".to_string());
writer.write("World".to_string());
// Read from the stream
while let Some(data) = stream.next().await {
println!("Received: {}", data);
}
Ok(())
}
#[cfg(feature = "stalled-monitor")]
use moosicbox_stream_utils::{ByteWriter, stalled_monitor::StalledReadMonitor};
#[cfg(feature = "stalled-monitor")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let writer = ByteWriter::default();
let stream = writer.stream();
// Add stalled read monitoring
let monitored_stream = stream.stalled_monitor();
// Use the monitored stream
// (monitoring behavior depends on the stalled_monitor implementation)
Ok(())
}
The stream utilities support some basic configuration:
The utilities handle common error scenarios:
futures::Stream trait