Skip to main content

ReadableDataSet

Trait ReadableDataSet 

Source
pub trait ReadableDataSet<E>: DataSet<E>
where E: Entity<Self::Value>,
{ // Required methods fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<IndexMap<Self::Id, E>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get<'life0, 'async_trait>( &'life0 self, id: impl 'async_trait + Into<Self::Id> + Send, ) -> Pin<Box<dyn Future<Output = Result<Option<E>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_some<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<(Self::Id, E)>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

Read-only access to typed entities with automatic deserialization.

This trait provides convenient access to entities without requiring knowledge of the underlying storage format. The implementation handles conversion from raw storage values to typed entities automatically.

§Performance Considerations

Entity deserialization has overhead compared to raw value access. For performance-critical scenarios, consider using crate::ReadableValueSet directly and handling deserialization manually or in batches.

§Example

use vantage_dataset::dataset::ReadableDataSet;

// Type-safe entity access
let all_users: IndexMap<String, User> = users.list().await?;
let specific_user: Option<User> = users.get(&user_id).await?;

// Sample data without loading everything
if let Some((id, user)) = users.get_some().await? {
    println!("Found user: {} with ID {}", user.name, id);
}

Required Methods§

Source

fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<IndexMap<Self::Id, E>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieve all entities with their IDs.

Returns an ordered map preserving insertion order where supported by the backend. Each storage value is automatically deserialized to the entity type.

§Performance Warning

This method loads all data into memory. Use with caution for large datasets. Consider implementing pagination for production use.

Source

fn get<'life0, 'async_trait>( &'life0 self, id: impl 'async_trait + Into<Self::Id> + Send, ) -> Pin<Box<dyn Future<Output = Result<Option<E>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieve a specific entity by ID.

Returns Ok(None) when no entity exists with the given ID. The storage value is automatically deserialized to the entity type.

§Errors

Returns an error only if the lookup itself fails (connection errors, deserialization failures). A missing row is not an error.

Source

fn get_some<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<(Self::Id, E)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieve one single entity from the set. If entities are ordered - return first entity.

Useful for sampling data or checking if the dataset contains any entities. Returns None if the dataset is empty.

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.

Implementors§

Source§

impl<E> ReadableDataSet<E> for ImTable<E>
where E: Entity, <E as TryFromRecord<Value>>::Error: Debug,

Source§

impl<T> ReadableDataSet<T> for CsvFile<T>
where T: Entity<AnyCsvType>,