pub trait Reader {
// Required methods
fn read(
&mut self,
handler: &mut impl FnMut(u32, &[u8]),
message_count: u16,
) -> Result<u32, ReadError>;
fn move_to(&mut self, position: u32) -> Result<u32, InvalidPosition>;
}
Expand description
The Reader
trait allows reading bytes from a kekbit channel. Implementers of this trait
are called ‘kekbit readers’. Usually a reader is bound to a given channel, and it is
expected that multiple readers will safely access the same channel simultaneous.
Required Methods§
Sourcefn read(
&mut self,
handler: &mut impl FnMut(u32, &[u8]),
message_count: u16,
) -> Result<u32, ReadError>
fn read( &mut self, handler: &mut impl FnMut(u32, &[u8]), message_count: u16, ) -> Result<u32, ReadError>
Accesses a number of records from the kekbit channel, and for each record, calls the given callback.
Returns the amount of bytes read from the channel
§Arguments
handler
- The callback function to be called when a record is pulled from the channel. The function will receive as parameters the position of the message in the channel, and the message in binary format.message_count
- A hint about how many records shall be read from the channel before the method completes. It is expected that this method will take from the channel at most this many records
§Errors
If this function fails, than an error variant will be returned. These errors are not expected to be recoverable. Once any error except Timeout
occurred, there will never be
data to read pass the current read marker. However reading from beginning of the channel to the current
read marker should still be a valid operation. The Timeout
exception,
may or may not be recoverable, depends on the channel Writer
behaviour.
Sourcefn move_to(&mut self, position: u32) -> Result<u32, InvalidPosition>
fn move_to(&mut self, position: u32) -> Result<u32, InvalidPosition>
Moves the reader to the given position in the channel if the position is valid and points to the beginning of a record. This method could be used by a reader to resume work from a previous session.
Returns the position if the operation succeeds
§Arguments
position
- The position in channel where we want the reader to point. The value is accounted from the beginning of the channel(e.g. a position of zero means the beginning of the channel). The position must be valid, it must be properly aligned, and is should point to the start of a record.
§Errors
If the channel is corrupted or the position is invalid a InvalidPosition will occur.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.