Skip to main content

LogSource

Trait LogSource 

Source
pub trait LogSource {
    // Required methods
    fn latest(
        &mut self,
        sensor_id: u16,
        buf: &mut [u8],
    ) -> Result<Option<(EntryHeader, usize)>, Error>;
    fn oldest(
        &mut self,
        sensor_id: u16,
        buf: &mut [u8],
    ) -> Result<Option<(EntryHeader, usize)>, Error>;
    fn count(&mut self, sensor_id: Option<u16>) -> Result<u32, Error>;
    fn query_range(
        &mut self,
        sensor_id: Option<u16>,
        t_start: u64,
        t_end: u64,
        callback: &mut dyn FnMut(&EntryHeader, &[u8]) -> bool,
    ) -> Result<u32, Error>;
}
Expand description

Somewhere sensor samples can be read back.

Payloads are delivered into a caller-provided buffer or to a callback, never allocated — this crate is no_std and has no allocator to reach for.

Required Methods§

Source

fn latest( &mut self, sensor_id: u16, buf: &mut [u8], ) -> Result<Option<(EntryHeader, usize)>, Error>

The most recent entry for a sensor, or None if it has none.

Returns the header and the payload length written into buf.

§Errors
  • BufferTooSmall if buf cannot hold the payload
Source

fn oldest( &mut self, sensor_id: u16, buf: &mut [u8], ) -> Result<Option<(EntryHeader, usize)>, Error>

The oldest retained entry for a sensor, or None if it has none.

§Errors
  • BufferTooSmall if buf cannot hold the payload
Source

fn count(&mut self, sensor_id: Option<u16>) -> Result<u32, Error>

Entries retained for a sensor, or for every sensor if None.

Source

fn query_range( &mut self, sensor_id: Option<u16>, t_start: u64, t_end: u64, callback: &mut dyn FnMut(&EntryHeader, &[u8]) -> bool, ) -> Result<u32, Error>

Entries whose timestamp lies in [t_start, t_end], in log order.

The callback returns false to stop, which stops after consuming the entry offered — the opposite of SensorDb::read_from, which is a replication stream rather than a query.

The callback is &mut dyn rather than a generic parameter so that this trait stays object-safe; the per-entry indirection is nothing beside the flash read that produced the entry.

§Returns

The number of entries delivered.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F, const PAGE_SIZE: usize, const MAX_SECTORS: usize> LogSource for SensorDb<F, PAGE_SIZE, MAX_SECTORS>

Source§

impl<S, C, const SP: usize, const SS: usize, const CP: usize, const CS: usize> LogSource for TieredDb<S, C, SP, SS, CP, CS>