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§
Sourcefn latest(
&mut self,
sensor_id: u16,
buf: &mut [u8],
) -> Result<Option<(EntryHeader, usize)>, Error>
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
BufferTooSmallifbufcannot hold the payload
Sourcefn oldest(
&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>
The oldest retained entry for a sensor, or None if it has none.
§Errors
BufferTooSmallifbufcannot hold the payload
Sourcefn count(&mut self, sensor_id: Option<u16>) -> Result<u32, Error>
fn count(&mut self, sensor_id: Option<u16>) -> Result<u32, Error>
Entries retained for a sensor, or for every sensor if None.
Sourcefn query_range(
&mut self,
sensor_id: Option<u16>,
t_start: u64,
t_end: u64,
callback: &mut dyn FnMut(&EntryHeader, &[u8]) -> bool,
) -> 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>
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".