pub trait InsertableDataSet<E>: DataSet<E>{
// Required method
fn insert_return_id<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 E,
) -> Pin<Box<dyn Future<Output = Result<Self::Id, VantageError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}Expand description
Append-only operations with automatic ID generation.
This trait is designed for storage backends that naturally generate unique IDs for new entities, such as message queues, event streams, or auto-incrementing database tables.
§Idempotency Considerations
Unlike other dataset operations, insert_return_id is not idempotent because
each call generates a new ID. Use this pattern only when:
- Your system can handle duplicate entities (event sourcing)
- You have application-level deduplication
- The storage naturally handles uniqueness (like message queues)
For idempotent operations, prefer WritableDataSet::insert with predetermined IDs.
§Example
use vantage_dataset::dataset::InsertableDataSet;
// Message queue scenario - each event gets unique ID
let event = UserLoginEvent {
user_id: "user-123".to_string(),
timestamp: Utc::now(),
ip_address: "192.168.1.1".to_string(),
};
let event_id = events.insert_return_id(event).await?;
println!("Generated event ID: {}", event_id);Required Methods§
Sourcefn insert_return_id<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 E,
) -> Pin<Box<dyn Future<Output = Result<Self::Id, VantageError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn insert_return_id<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 E,
) -> Pin<Box<dyn Future<Output = Result<Self::Id, VantageError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Insert an entity and return the generated ID.
The storage backend generates a unique identifier for the new entity. The entity is automatically serialized to the storage format.
§Warning
This method is not idempotent - each call creates a new entity with a new ID, even if the entity data is identical.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".