pub trait WritableDataSet<E>: DataSet<E>{
// Required methods
fn insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
entity: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn replace<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
entity: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn patch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
partial: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
Write operations on typed entities with automatic serialization.
This trait provides convenient write operations that automatically handle entity serialization to the storage format. All operations follow idempotent patterns safe for retry in distributed systems.
§Serialization Behavior
Entities are automatically serialized to the storage’s Value type before
persistence. The serialization format depends on your storage backend:
- JSON databases use
serde_jsonserialization - Binary stores may use CBOR or custom formats
- Document databases preserve nested structure
§Idempotency Guarantees
All write operations are designed to be safely retryable:
insert: No-op if ID already existsreplace: Always succeeds, overwrites existing datapatch: Atomic update, fails if entity doesn’t exist
§Example
use vantage_dataset::dataset::WritableDataSet;
let user = User {
name: "Alice".to_string(),
email: "alice@example.com".to_string(),
age: 30,
};
// Idempotent insert
users.insert(&"user-123".to_string(), user.clone()).await?;
// Update specific fields
let mut updated_user = user;
updated_user.age = 31;
users.replace(&"user-123".to_string(), updated_user).await?;Required Methods§
Sourcefn insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
entity: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
entity: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Insert entity with a specific ID (often generated) (HTTP POST with ID)
Idempotent: Succeeds if no entity exists with the given ID. If entity already exists, must return success without overwriting data, returning original data.
Returns: Entity as it was stored.
§Use Case
Generate unique ID and store centity while avoiding duplicates.
Sourcefn replace<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
entity: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn replace<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
entity: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Replace the entire entity at the specified ID (HTTP PUT)
Idempotent: Always succeeds, completely overwrites existing data
if present. If possible, will remove/recreate entity; therefore if
entity doesn’t contain certain attributes which were present in the
database, those will be removed. If entity does not exist, will
create it.
Returns: entity as it was stored.
§Use Case
Replace with a new version of a entity.
Sourcefn patch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
partial: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn patch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 Self::Id,
partial: &'life2 E,
) -> Pin<Box<dyn Future<Output = Result<E>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Partially update an entity by merging with the provided data (HTTP PATCH)
Fails if entity doesn’t exist. The exact merge behavior depends on the storage implementation - typically merges object fields for JSON-like values.
Returns: entity as it was stored (not only the partial change).
§Use Case
Update only the modified fields of a entity.
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.