pub trait Store {
// Required methods
fn append(
&mut self,
record: &[u8],
) -> impl Future<Output = Result<()>> + Send;
fn peek(&self) -> impl Future<Output = Result<Option<Vec<u8>>>> + Send;
fn pop(&mut self) -> impl Future<Output = Result<Option<Vec<u8>>>> + Send;
fn len(&self) -> impl Future<Output = Result<usize>> + Send;
// Provided methods
fn append_text(
&mut self,
text: &str,
) -> impl Future<Output = Result<()>> + Send { ... }
fn peek_text(&self) -> impl Future<Output = Result<Option<String>>> + Send
where Self: Sync { ... }
fn pop_text(
&mut self,
) -> impl Future<Output = Result<Option<String>>> + Send
where Self: Send { ... }
fn is_empty(&self) -> impl Future<Output = Result<bool>> + Send
where Self: Sync { ... }
}Expand description
A durable, first-in first-out queue for store-and-forward buffering.
Records are appended while a device is offline and drained in order when a link becomes available, letting applications tolerate intermittent connectivity without losing data.
The returned futures are Send, for the same reason a Transport’s are: a
transport ladder buffers into a store and is itself a transport, so a task on a
multi-threaded runtime can drive it. An implementation written as async fn
satisfies this as long as everything it holds across an await is Send.
Required Methods§
Sourcefn peek(&self) -> impl Future<Output = Result<Option<Vec<u8>>>> + Send
fn peek(&self) -> impl Future<Output = Result<Option<Vec<u8>>>> + Send
Returns the oldest record without removing it.
This lets a forwarder send a record before committing to its removal, so a failed send can leave the record buffered in order rather than dropping it.
§Returns
Some(record) containing the oldest buffered bytes, or None if the queue
is empty.
§Errors
Returns Error::Io if the queue cannot be read.
Provided Methods§
Sourcefn append_text(&mut self, text: &str) -> impl Future<Output = Result<()>> + Send
fn append_text(&mut self, text: &str) -> impl Future<Output = Result<()>> + Send
Appends text to the back of the queue: a reading or a line written out.
This is append with the text’s UTF-8 bytes, so a queue of
readings needs no encoding step; peek_text and
pop_text read them back.
§Arguments
text- the text to persist.
§Returns
Ok(()) once the record is durably stored.
§Errors
Whatever append returns.
Sourcefn peek_text(&self) -> impl Future<Output = Result<Option<String>>> + Sendwhere
Self: Sync,
fn peek_text(&self) -> impl Future<Output = Result<Option<String>>> + Sendwhere
Self: Sync,
Returns the oldest record as text, without removing it.
It borrows the store across an await, so it asks for Sync, which a store
whose own futures are Send already is.
§Returns
Some(text) for the oldest record, or None if the queue is empty.
§Errors
Whatever peek returns, or
Error::Codec if the record is not UTF-8 text.
Sourcefn pop_text(&mut self) -> impl Future<Output = Result<Option<String>>> + Sendwhere
Self: Send,
fn pop_text(&mut self) -> impl Future<Output = Result<Option<String>>> + Sendwhere
Self: Send,
Removes and returns the oldest record as text.
§Returns
Some(text) for the oldest record, or None if the queue is empty.
§Errors
Whatever pop returns, or
Error::Codec if the record is not UTF-8 text.
Sourcefn is_empty(&self) -> impl Future<Output = Result<bool>> + Sendwhere
Self: Sync,
fn is_empty(&self) -> impl Future<Output = Result<bool>> + Sendwhere
Self: Sync,
Returns whether the queue currently holds no records.
The default implementation reports whether len is zero. It
borrows the store across an await, so it asks for Sync, which a store whose
own futures are Send already is.
§Returns
true if the queue is empty, false otherwise.
§Errors
Returns Error::Io if the queue length cannot be
determined.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".