Skip to main content

SensorLoggerAsync

Struct SensorLoggerAsync 

Source
pub struct SensorLoggerAsync<L, Clock>
where Clock: Fn() -> u64,
{ /* private fields */ }
Expand description

Async version of SensorLogger, wrapping any LogSinkAsync.

All logging methods are async fn and take &mut self. For query access, use sink_mut() to reach the wrapped log.

§Example

ⓘ
use sensor_db::{SensorDbAsync, SensorLoggerAsync};

let db: SensorDbAsync<_, 256, 32> = SensorDbAsync::new(flash, 0, 32, 2)?;
let mut logger = SensorLoggerAsync::new(db, || get_timestamp_us());

logger.log(&Temperature { celsius: 25.5 }).await?;
logger.sync().await?;

Implementations§

Source§

impl<L, Clock> SensorLoggerAsync<L, Clock>
where L: LogSinkAsync, Clock: Fn() -> u64,

Source

pub fn new(sink: L, clock: Clock) -> Self

Create a new SensorLoggerAsync wrapping an existing log.

§Arguments
  • sink: A mounted (or freshly formatted) async log
  • clock: Function returning the current timestamp as u64
Source

pub async fn log<T: SensorData>(&mut self, data: &T) -> Result<(), Error>

Log a typed sensor reading with an auto-generated timestamp.

The sensor ID is derived from T::SENSOR_ID.

Source

pub async fn log_raw( &mut self, sensor_id: u16, payload: &[u8], ) -> Result<(), Error>

Log a raw payload with an auto-generated timestamp.

§Arguments
  • sensor_id: Sensor identifier
  • payload: Raw sensor data bytes
Source

pub async fn log_value<T: IntoBytes + Immutable>( &mut self, sensor_id: u16, data: &T, ) -> Result<(), Error>

Log a typed value with an explicit sensor ID and auto-generated timestamp.

This is the Layer 1 equivalent — you provide the sensor ID, the clock provides the timestamp.

Source

pub async fn sync(&mut self) -> Result<(), Error>

Flush the page buffer to flash.

Delegates to LogSinkAsync::sync.

Source

pub fn sink_mut(&mut self) -> &mut L

Mutable access to the wrapped log.

Every async read takes &mut self, so this is the accessor to reach for — unlike the blocking logger, where sink() covers reads.

Source

pub fn sink(&self) -> &L

Immutable access to the wrapped log.

Only useful for non-flash methods like stats(), is_mounted(), and max_payload_size().

Source

pub fn into_inner(self) -> (L, Clock)

Consume the logger and return the wrapped log and clock.

Auto Trait Implementations§

§

impl<L, Clock> Freeze for SensorLoggerAsync<L, Clock>
where L: Freeze, Clock: Freeze,

§

impl<L, Clock> RefUnwindSafe for SensorLoggerAsync<L, Clock>
where L: RefUnwindSafe, Clock: RefUnwindSafe,

§

impl<L, Clock> Send for SensorLoggerAsync<L, Clock>
where L: Send, Clock: Send,

§

impl<L, Clock> Sync for SensorLoggerAsync<L, Clock>
where L: Sync, Clock: Sync,

§

impl<L, Clock> Unpin for SensorLoggerAsync<L, Clock>
where L: Unpin, Clock: Unpin,

§

impl<L, Clock> UnsafeUnpin for SensorLoggerAsync<L, Clock>
where L: UnsafeUnpin, Clock: UnsafeUnpin,

§

impl<L, Clock> UnwindSafe for SensorLoggerAsync<L, Clock>
where L: UnwindSafe, Clock: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.