Skip to main content

DataSet

Trait DataSet 

Source
pub trait DataSet<E>: ValueSet
where E: Entity<Self::Value>,
{ }
Expand description

Entity-aware dataset operations built on top of the ValueSet foundation.

DataSet bridges the gap between raw storage values and typed Rust entities, providing automatic serialization/deserialization while preserving the flexibility of the underlying storage backend.

§Type Parameters

  • E: The entity type that implements Entity trait, typically your domain models

§Relationship to ValueSet

While ValueSet works with raw storage values (JSON, CBOR, etc.), DataSet adds a typed layer that handles conversion between entities and storage format:

Entity <--serde--> Value <--storage--> Backend

This separation allows the same storage backend to efficiently support both raw value operations and typed entity operations as needed.

§Implementation Strategy

Implement the specific capability traits your data source supports:

  • ReadableDataSet for read-only sources (CSV files, APIs)
  • InsertableDataSet for append-only sources (message queues, logs)
  • WritableDataSet for full CRUD sources (databases, caches)
  • entityDataSet for change-tracking scenarios (interactive applications)

§Example

use vantage_dataset::dataset::{DataSet, ReadableDataSet, WritableDataSet};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone)]
struct User {
    name: String,
    email: String,
    age: u32,
}

// Your storage implementation
struct UserTable;

impl ValueSet for UserTable {
    type Id = String;
    type Value = serde_json::Value;
}

impl DataSet<User> for UserTable {}

impl ReadableDataSet<User> for UserTable {
    async fn list(&self) -> Result<IndexMap<String, User>> {
        // Implementation converts storage values to entities
    }
}

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> DataSet<E> for ImTable<E>
where E: Entity,

Source§

impl<E> DataSet<E> for Topic<E>
where E: Entity,

Source§

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