Skip to main content

LogSourceExt

Trait LogSourceExt 

Source
pub trait LogSourceExt: LogSource {
    // Provided methods
    fn latest_sensor<T: SensorData>(
        &mut self,
    ) -> Result<Option<(EntryHeader, T)>, Error> { ... }
    fn oldest_sensor<T: SensorData>(
        &mut self,
    ) -> Result<Option<(EntryHeader, T)>, Error> { ... }
    fn count_sensor<T: SensorData>(&mut self) -> Result<u32, Error> { ... }
    fn query_sensor<T: SensorData, C>(
        &mut self,
        t_start: u64,
        t_end: u64,
        callback: C,
    ) -> Result<u32, Error>
       where C: FnMut(&EntryHeader, &T) -> bool { ... }
    fn query_all_sensor<T: SensorData, C>(
        &mut self,
        callback: C,
    ) -> Result<u32, Error>
       where C: FnMut(&EntryHeader, &T) -> bool { ... }
}
Expand description

Typed conveniences over any LogSource.

§What counts as a T

A typed payload is the type’s SCHEMA_VERSION followed by size_of::<T>() bytes, so an entry stored under T::SENSOR_ID qualifies only if both agree. The single-entry reads deserialise into a Tagged<T>-sized buffer and say which half failed: a wrong length reports SizeMismatch when short and BufferTooSmall when long, a wrong version reports SchemaMismatch naming the version found.

query_sensor instead skips entries that are not a T, because a query that aborted on the first stale entry could never reach the good ones behind it. That is also the migration path: two types sharing a sensor ID at different versions each read their own era.

The header handed back describes the entry, so its payload_len counts the schema tag as well as the value.

Provided Methods§

Source

fn latest_sensor<T: SensorData>( &mut self, ) -> Result<Option<(EntryHeader, T)>, Error>

The most recent value for a sensor type.

Source

fn oldest_sensor<T: SensorData>( &mut self, ) -> Result<Option<(EntryHeader, T)>, Error>

The oldest retained value for a sensor type.

Source

fn count_sensor<T: SensorData>(&mut self) -> Result<u32, Error>

Entries retained for a sensor type.

Source

fn query_sensor<T: SensorData, C>( &mut self, t_start: u64, t_end: u64, callback: C, ) -> Result<u32, Error>
where C: FnMut(&EntryHeader, &T) -> bool,

Values for a sensor type whose timestamp lies in [t_start, t_end].

§Returns

The number of entries delivered — entries skipped for a wrong schema version or payload length are not counted.

Source

fn query_all_sensor<T: SensorData, C>( &mut self, callback: C, ) -> Result<u32, Error>
where C: FnMut(&EntryHeader, &T) -> bool,

Every retained value for a sensor type, in log order.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§