DatabaseAtRevisionTyped

Trait DatabaseAtRevisionTyped 

Source
pub trait DatabaseAtRevisionTyped: DatabaseAtRevision {
    // Required methods
    fn view_state_as<T>(
        &self,
        name: &StateViewName,
        version: StateViewVersion,
    ) -> impl Future<Output = Result<T, StateViewError>>
       where T: DeserializeOwned;
    fn view_state_opt<T>(
        &self,
        name: &StateViewName,
        version: StateViewVersion,
    ) -> impl Future<Output = Result<Option<T>, StateViewError>>
       where T: DeserializeOwned;
}
Expand description

Extension trait for typed state view access.

This trait provides convenience methods for fetching state views and automatically deserializing them to typed Rust structs.

Required Methods§

Source

fn view_state_as<T>( &self, name: &StateViewName, version: StateViewVersion, ) -> impl Future<Output = Result<T, StateViewError>>

Fetch a state view and deserialize it to the specified type.

§Example
#[derive(Deserialize)]
struct AccountSummary {
    balance: i64,
    transaction_count: u32,
}

let summary: AccountSummary = db
    .view_state_as::<AccountSummary>(&StateViewName::new("account-summary")?, 1)
    .await?;
Source

fn view_state_opt<T>( &self, name: &StateViewName, version: StateViewVersion, ) -> impl Future<Output = Result<Option<T>, StateViewError>>

Fetch a state view and deserialize it, returning None if not found.

This is useful when the state view might not exist yet (e.g., before any events have been recorded for an 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.

Implementors§