pub struct Stream { /* private fields */ }Expand description
A streaming session for outputting point chunks to a DAC.
The stream provides two modes of operation:
- Blocking mode: Call
next_request()to get what to produce, thenwrite(). - Callback mode: Call
run()with a producer closure.
The stream owns pacing, backpressure, and the timebase (StreamInstant).
Implementations§
Source§impl Stream
impl Stream
Sourcepub fn config(&self) -> &StreamConfig
pub fn config(&self) -> &StreamConfig
Returns the stream configuration.
Sourcepub fn control(&self) -> StreamControl
pub fn control(&self) -> StreamControl
Returns a thread-safe control handle.
Sourcepub fn chunk_points(&self) -> usize
pub fn chunk_points(&self) -> usize
The resolved chunk size chosen for this stream.
This is fixed for the lifetime of the stream.
Sourcepub fn status(&self) -> Result<StreamStatus>
pub fn status(&self) -> Result<StreamStatus>
Returns the current stream status.
Sourcepub fn next_request(&mut self) -> Result<ChunkRequest>
pub fn next_request(&mut self) -> Result<ChunkRequest>
Blocks until the stream wants the next chunk.
Returns a ChunkRequest describing exactly what to produce.
The producer must return exactly req.n_points points.
Sourcepub fn write(&mut self, req: &ChunkRequest, points: &[LaserPoint]) -> Result<()>
pub fn write(&mut self, req: &ChunkRequest, points: &[LaserPoint]) -> Result<()>
Writes exactly req.n_points points for the given request.
If the device cannot accept data immediately (backpressure), this method retries automatically with brief sleeps until the write succeeds or the stream is stopped.
§Contract
points.len()must equalreq.n_points.- The request must be the most recent one from
next_request().
§Shutter Control
This method manages the hardware shutter based on arm state transitions:
- When transitioning from armed to disarmed, the shutter is closed (best-effort).
- When transitioning from disarmed to armed, the shutter is opened (best-effort).
Sourcepub fn stop(&mut self) -> Result<()>
pub fn stop(&mut self) -> Result<()>
Stop the stream and terminate output.
Disarms the output (software blanking + hardware shutter) before stopping
the backend to prevent the “freeze on last bright point” hazard.
Use disarm() instead if you want to keep the stream alive but safe.
Sourcepub fn into_dac(self) -> (Dac, StreamStats)
pub fn into_dac(self) -> (Dac, StreamStats)
Consume the stream and recover the device for reuse.
This method disarms and stops the stream (software blanking + hardware shutter),
then returns the underlying Dac along with the final StreamStats.
The device can then be used to start a new stream with different configuration.
§Example
let (stream, info) = device.start_stream(config)?;
// ... stream for a while ...
let (device, stats) = stream.into_dac();
println!("Streamed {} points", stats.points_written);
// Restart with different config
let new_config = StreamConfig::new(60_000);
let (stream2, _) = device.start_stream(new_config)?;Sourcepub fn run<F, E>(self, producer: F, on_error: E) -> Result<RunExit>where
F: FnMut(ChunkRequest) -> Option<Vec<LaserPoint>> + Send + 'static,
E: FnMut(Error) + Send + 'static,
pub fn run<F, E>(self, producer: F, on_error: E) -> Result<RunExit>where
F: FnMut(ChunkRequest) -> Option<Vec<LaserPoint>> + Send + 'static,
E: FnMut(Error) + Send + 'static,
Run the stream in callback mode.
The producer is called whenever the stream needs a new chunk.
Return Some(points) to continue, or None to end the stream.
§Error Classification
The on_error callback receives recoverable errors that don’t terminate the stream.
Terminal conditions result in returning from run():
RunExit::Stopped: Stream was stopped viaStreamControl::stop()or underrun policy.RunExit::ProducerEnded: Producer returnedNone.RunExit::Disconnected: Device disconnected or became unreachable.
Recoverable errors (reported via on_error, stream continues):
- Transient backend errors that don’t indicate disconnection.