Trait DeviceStreamExt

Source
pub trait DeviceStreamExt {
    // Required methods
    fn stream(self: Arc<Self>) -> ReadingStream;
    fn stream_with_options(
        self: Arc<Self>,
        options: StreamOptions,
    ) -> ReadingStream;
}
Expand description

Extension trait for Device to create reading streams.

Note: This trait requires Arc<Self> because the stream’s background task needs to hold a reference to the device that outlives the method call.

§Example

use std::sync::Arc;
use aranet_core::{Device, DeviceStreamExt};
use futures::StreamExt;

// Wrap device in Arc for streaming
let device = Arc::new(Device::connect("Aranet4 12345").await?);

// Create a stream and consume readings
let mut stream = device.stream();
while let Some(result) = stream.next().await {
    match result {
        Ok(reading) => println!("CO2: {} ppm", reading.co2),
        Err(e) => eprintln!("Error: {}", e),
    }
}

Required Methods§

Source

fn stream(self: Arc<Self>) -> ReadingStream

Create a reading stream with default options.

Polls the device every second and buffers up to 16 readings.

Source

fn stream_with_options(self: Arc<Self>, options: StreamOptions) -> ReadingStream

Create a reading stream with custom options.

Implementors§