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§
Required Methods§
Sourcefn with_read_typed<R, T, F>(
&self,
sys_id: SysId,
f: F,
) -> Result<Option<T>, Self::Error>
fn with_read_typed<R, T, F>( &self, sys_id: SysId, f: F, ) -> Result<Option<T>, Self::Error>
Reads a generated record by system id.
Sourcefn with_read_typed_by_pk<R, P, T, F>(
&self,
pk: P,
f: F,
) -> Result<Option<T>, Self::Error>
fn with_read_typed_by_pk<R, P, T, F>( &self, pk: P, f: F, ) -> Result<Option<T>, Self::Error>
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.
Sourcefn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, Self::Error>
fn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, Self::Error>
Creates a generated record.
Sourcefn update_typed_by_pk<R, P, T, F>(
&mut self,
pk: P,
f: F,
) -> Result<Option<T>, Self::Error>
fn update_typed_by_pk<R, P, T, F>( &mut self, pk: P, f: F, ) -> Result<Option<T>, Self::Error>
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.
Sourcefn delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, Self::Error>
fn delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, Self::Error>
Deletes a generated record by primary key.
Sourcefn emit_typed_event<E>(&mut self, payload: Vec<u8>)where
E: GeneratedEventAccess,
fn emit_typed_event<E>(&mut self, payload: Vec<u8>)where
E: GeneratedEventAccess,
Emits a generated event payload.
Sourcefn for_each_record_key(&self, kind: RecordKind, f: &mut dyn FnMut(RecordKey))
fn for_each_record_key(&self, kind: RecordKind, f: &mut dyn FnMut(RecordKey))
Iterates record keys for one record kind.
Provided Methods§
Sourcefn 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 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.
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.
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.