Skip to main content

TypedTxContext

Trait TypedTxContext 

Source
pub trait TypedTxContext {
    type Error;

    // Required methods
    fn with_read_typed<R, T, F>(
        &self,
        sys_id: SysId,
        f: F,
    ) -> Result<Option<T>, Self::Error>
       where R: GeneratedRecordAccess,
             F: FnOnce(R::Access<'_>) -> T;
    fn with_read_typed_by_pk<R, P, T, F>(
        &self,
        pk: P,
        f: F,
    ) -> Result<Option<T>, Self::Error>
       where R: GeneratedRecordAccess,
             P: AsRef<[u8]>,
             F: FnOnce(R::Access<'_>) -> T;
    fn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, Self::Error>
       where R: GeneratedRecordAccess,
             F: for<'b> FnOnce(&mut R::NewBuilder<'b>);
    fn update_typed_by_pk<R, P, T, F>(
        &mut self,
        pk: P,
        f: F,
    ) -> Result<Option<T>, Self::Error>
       where R: GeneratedRecordAccess,
             P: AsRef<[u8]>,
             F: for<'b> FnOnce(&mut R::UpdateBuilder<'b>) -> T;
    fn delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, Self::Error>
       where R: GeneratedRecordAccess,
             P: AsRef<[u8]>;
    fn emit_typed_event<E>(&mut self, payload: Vec<u8>)
       where E: GeneratedEventAccess;
    fn for_each_record_key(
        &self,
        kind: RecordKind,
        f: &mut dyn FnMut(RecordKey),
    );

    // Provided methods
    fn update_or_create_typed_by_pk<R, P, T, FU, FC>(
        &mut self,
        pk: P,
        update: FU,
        create: FC,
    ) -> Result<T, Self::Error>
       where R: GeneratedRecordAccess,
             P: AsRef<[u8]>,
             FU: for<'b> FnOnce(&mut R::UpdateBuilder<'b>) -> T,
             FC: for<'b> FnOnce(&mut R::NewBuilder<'b>) -> T { ... }
    fn debug_log(&mut self, _message: String) { ... }
}
Expand description

Typed transaction convenience API over generated StateVec accessors.

Required Associated Types§

Source

type Error

Host error type.

Required Methods§

Source

fn with_read_typed<R, T, F>( &self, sys_id: SysId, f: F, ) -> Result<Option<T>, Self::Error>
where R: GeneratedRecordAccess, F: FnOnce(R::Access<'_>) -> T,

Reads a generated record by system id.

Source

fn with_read_typed_by_pk<R, P, T, F>( &self, pk: P, f: F, ) -> Result<Option<T>, Self::Error>
where R: GeneratedRecordAccess, P: AsRef<[u8]>, F: FnOnce(R::Access<'_>) -> T,

Read a record by primary key without mutating it.

Prefer TypedTxContext::update_typed_by_pk when the next step is to modify the same record. The update path keeps the operation in-place and avoids the extra resolve/read/then-update round-trip that this read-first pattern introduces on hot paths.

Source

fn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, Self::Error>
where R: GeneratedRecordAccess, F: for<'b> FnOnce(&mut R::NewBuilder<'b>),

Creates a generated record.

Source

fn update_typed_by_pk<R, P, T, F>( &mut self, pk: P, f: F, ) -> Result<Option<T>, Self::Error>
where R: GeneratedRecordAccess, P: AsRef<[u8]>, F: for<'b> FnOnce(&mut R::UpdateBuilder<'b>) -> T,

Update a record in-place by primary key.

This is the preferred hot-path API when a command needs to modify an existing record. It avoids the read-then-update pattern that would otherwise resolve the primary key and touch the same record twice.

Source

fn delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, Self::Error>
where R: GeneratedRecordAccess, P: AsRef<[u8]>,

Deletes a generated record by primary key.

Source

fn emit_typed_event<E>(&mut self, payload: Vec<u8>)

Emits a generated event payload.

Source

fn for_each_record_key(&self, kind: RecordKind, f: &mut dyn FnMut(RecordKey))

Iterates record keys for one record kind.

Provided Methods§

Source

fn update_or_create_typed_by_pk<R, P, T, FU, FC>( &mut self, pk: P, update: FU, create: FC, ) -> Result<T, Self::Error>
where R: GeneratedRecordAccess, P: AsRef<[u8]>, FU: for<'b> FnOnce(&mut R::UpdateBuilder<'b>) -> T, FC: for<'b> FnOnce(&mut R::NewBuilder<'b>) -> T,

Updates an existing record by primary key or creates a new one.

Source

fn debug_log(&mut self, _message: String)

Emits host-side diagnostic text.

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 TypedTxContext for dyn RuntimeHostContext + '_

Bridge dyn RuntimeHostContext to TypedTxContext so that command_dispatch!-generated code can operate on plugin-facing host adapters without requiring engine-internal raw transaction capabilities.

Source§

impl<Ctx: TxContext + ?Sized> TypedTxContext for Ctx