pub trait Writer<D: DataFormat> {
// Required methods
fn write(&mut self, data: &impl Encodable<D>) -> Result<u32, WriteError>;
fn heartbeat(&mut self) -> Result<u32, WriteError>;
// Provided method
fn flush(&mut self) -> Result<(), Error> { ... }
}
Expand description
The Writer
trait allows writing chunk of bytes as records into a kekbit channel.
Implementers of this trait are called ‘kekbit writers’. Usually a writer is bound to
a given channel, and it is expected that there is only one writer which directly writes into the channel, however
multiple writers may cooperate during the writing process. For any given channel a DataFormat must be specified.
Required Methods§
Sourcefn write(&mut self, data: &impl Encodable<D>) -> Result<u32, WriteError>
fn write(&mut self, data: &impl Encodable<D>) -> Result<u32, WriteError>
Writes a given record to a kekbit channel.
Returns the total amount of bytes wrote into the channel or a WriteError
if the write operation fails.
§Arguments
data
- information to be encoded and pushed into channel.
§Errors
If the operation fails, than an error variant will be returned. Some errors such EncodingError or NoSpaceForRecord may allow future writes to succeed while others such ChannelFull signals the end of life for the channel.
Sourcefn heartbeat(&mut self) -> Result<u32, WriteError>
fn heartbeat(&mut self) -> Result<u32, WriteError>
Writes into the stream a heartbeat message. This method shall be used by all writers which want to respect to timeout interval associated to a channel. Hearbeating is the expected mechanism by which a channel writer will keep the active readers interested in the data published on the channel. Heartbeat shall be done regularly at a time interval which ensures that at least one heartbeat is sent between any two ‘timeout’ long intervals.
Returns the total amount of bytes wrote into the channel or a WriteError
if the write operation fails.
§Errors
If this call fails than an error variant will be returned. The errors are not recoverable, they signal that the channel had reached the end of its lifetime.
Provided Methods§
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.