pub struct Data<T> { /* private fields */ }Expand description
A cloneable, type-erased handle to a Dataset.
Implementations§
Source§impl<T: Send + 'static> Data<T>
impl<T: Send + 'static> Data<T>
Sourcepub async fn write_all(&self, items: impl IntoIterator<Item = T>) -> Result<()>
pub async fn write_all(&self, items: impl IntoIterator<Item = T>) -> Result<()>
Stores every item of items at once, see Dataset::write_batch.
§Errors
Returns an error if the underlying dataset fails.
Sourcepub async fn read(&self) -> Result<Option<T>>
pub async fn read(&self) -> Result<Option<T>>
Takes the next item, or None if the dataset is empty.
§Errors
Returns an error if the underlying dataset fails.
Sourcepub async fn read_batch(&self, max: usize) -> Result<Vec<T>>
pub async fn read_batch(&self, max: usize) -> Result<Vec<T>>
Takes up to max items at once, see Dataset::read_batch.
§Errors
Returns an error if the underlying dataset fails.
Sourcepub async fn read_all(&self) -> Result<Vec<T>>
pub async fn read_all(&self) -> Result<Vec<T>>
Takes every item until the dataset is empty, in batches of 1024 items.
§Errors
Returns an error if the underlying dataset fails.
Sourcepub fn into_stream(self) -> impl Stream<Item = Result<T>> + Send
pub fn into_stream(self) -> impl Stream<Item = Result<T>> + Send
Returns a stream that takes items one at a time until the dataset is
empty, so it never takes an item it does not yield. To drain a large
dataset, into_batches takes fewer trips to
its storage.
Sourcepub fn into_batches(
self,
max: usize,
) -> impl Stream<Item = Result<Vec<T>>> + Send
pub fn into_batches( self, max: usize, ) -> impl Stream<Item = Result<Vec<T>>> + Send
Returns a stream that takes batches of up to max items, see
Dataset::read_batch, until the dataset is empty.
Trait Implementations§
Source§impl<T: Send + 'static> Dataset<T> for Data<T>
impl<T: Send + 'static> Dataset<T> for Data<T>
Source§fn write_batch(&self, items: Vec<T>) -> impl Future<Output = Result<()>> + Send
fn write_batch(&self, items: Vec<T>) -> impl Future<Output = Result<()>> + Send
Source§fn read(&self) -> impl Future<Output = Result<Option<T>>> + Send
fn read(&self) -> impl Future<Output = Result<Option<T>>> + Send
None if the dataset is empty. Read more