pub trait ActiveEntitySet<E>: ReadableDataSet<E> + WritableDataSet<E>where
E: Entity<Self::Value> + IntoRecord<Self::Value> + TryFromRecord<Self::Value> + Send + Sync + Clone,{
// Provided methods
fn get_entity<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
) -> Pin<Box<dyn Future<Output = Result<Option<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn list_entities<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn get_some_entity<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn new_entity(&self, id: Self::Id, entity: E) -> ActiveEntity<'_, Self, E> { ... }
}Expand description
Change tracking for typed entities with automatic persistence.
This trait extends readable and writable datasets with a “entity” pattern that tracks entity modifications and enables deferred persistence. entities act as smart wrappers around entities that know how to save themselves back to storage.
§entity Pattern Benefits
- Change tracking: Only modified fields are serialized and persisted
- Type safety: Work with native Rust entities, not raw values
- Optimistic locking: Conflict detection in concurrent scenarios
- Deferred persistence: Batch multiple changes before saving
- Interactive editing: Perfect for UI scenarios with undo/redo
§Example
use vantage_dataset::dataset::entityDataSet;
// Get entity for interactive editing
let mut user_entity = users.get_entity(&user_id).await?.unwrap();
// Modify through standard field access
user_entity.name = "Alice Smith".to_string();
user_entity.age = 31;
// Changes are automatically tracked and persisted
user_entity.save().await?;
// Or work with multiple entities
let mut entities = users.list_entities().await?;
for mut entity in entities {
entity.status = Status::Processed;
entity.save().await?; // Each saves independently
}Provided Methods§
Sourcefn get_entity<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
) -> Pin<Box<dyn Future<Output = Result<Option<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_entity<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
) -> Pin<Box<dyn Future<Output = Result<Option<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieve an entity wrapped for change tracking and deferred persistence.
The returned entity can be modified in-place and will track all
changes for efficient persistence when save() is called.
§Example
let mut user = table.get_entity(&"user123".to_string()).await?
.unwrap_or_else(|| table.new_entity("user123".to_string(), User {
id: Some("user123".to_string()),
name: "Default User".to_string(),
active: false,
}));
user.active = true;
user.save().await?;§Returns
Ok(Some(entity)): Entity wrapper with change trackingOk(None): entity doesn’t existErr: Storage or deserialization error
Sourcefn list_entities<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn list_entities<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Retrieve all entities wrapped for change tracking.
Each returned entity operates independently - modifications to one
entity don’t affect others, and each must be saved separately.
§Performance Note
This loads and deserializes all entities into memory. Consider pagination or streaming approaches for large datasets.
Sourcefn get_some_entity<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn get_some_entity<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<ActiveEntity<'_, Self, E>>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Retrieve some entity wrapped for change tracking and deferred persistence.
This is equivalent to get_some() but returns an ActiveEntity wrapper.
§Returns
Ok(Some(entity)): Entity wrapper with change trackingOk(None): no entities exist in the datasetErr: Storage or deserialization error
Sourcefn new_entity(&self, id: Self::Id, entity: E) -> ActiveEntity<'_, Self, E>
fn new_entity(&self, id: Self::Id, entity: E) -> ActiveEntity<'_, Self, E>
Create a new entity with the provided data.
This method creates a new entity and returns it wrapped as an ActiveEntity.
The entity is not automatically saved - call .save() to persist it.
§Parameters
id: The ID for the new entityentity: The entity data
§Returns
ActiveEntity: New entity wrapper ready for modification and saving
§Example
let mut user = table.get_entity(&"user123".to_string()).await?
.unwrap_or_else(|| table.new_entity("user123".to_string(), User {
id: Some("user123".to_string()),
name: "Default User".to_string(),
active: false,
}));
user.active = true;
user.save().await?;§Note
This method does not check if an entity with the given ID already exists.
Use in combination with get_entity() for get-or-create patterns.
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.