Skip to main content

Stream

Struct Stream 

Source
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, then write().
  • Callback mode: Call run() with a producer closure.

The stream owns pacing, backpressure, and the timebase (StreamInstant).

Implementations§

Source§

impl Stream

Source

pub fn info(&self) -> &DacInfo

Returns the device info.

Source

pub fn config(&self) -> &StreamConfig

Returns the stream configuration.

Source

pub fn control(&self) -> StreamControl

Returns a thread-safe control handle.

Source

pub fn chunk_points(&self) -> usize

The resolved chunk size chosen for this stream.

This is fixed for the lifetime of the stream.

Source

pub fn status(&self) -> Result<StreamStatus>

Returns the current stream status.

Source

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.

Source

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 equal req.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).
Source

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.

Source

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)?;
Source

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 via StreamControl::stop() or underrun policy.
  • RunExit::ProducerEnded: Producer returned None.
  • RunExit::Disconnected: Device disconnected or became unreachable.

Recoverable errors (reported via on_error, stream continues):

  • Transient backend errors that don’t indicate disconnection.

Trait Implementations§

Source§

impl Drop for Stream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Stream

§

impl !RefUnwindSafe for Stream

§

impl Send for Stream

§

impl !Sync for Stream

§

impl Unpin for Stream

§

impl !UnwindSafe for Stream

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.