pub trait RuntimeHostContextExt: RuntimeHostContext {
// Provided methods
fn with_read_typed<R, T, F>(
&self,
sys_id: SysId,
f: F,
) -> Result<Option<T>, RuntimeHostError>
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>, RuntimeHostError>
where R: GeneratedRecordAccess,
P: AsRef<[u8]>,
F: FnOnce(R::Access<'_>) -> T { ... }
fn create_typed<R, F>(
&mut self,
init: F,
) -> Result<RecordKey, RuntimeHostError>
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>, RuntimeHostError>
where R: GeneratedRecordAccess,
P: AsRef<[u8]>,
F: for<'b> FnOnce(&mut R::UpdateBuilder<'b>) -> T { ... }
fn update_or_create_typed_by_pk<R, P, T, FU, FC>(
&mut self,
pk: P,
update: FU,
create: FC,
) -> Result<T, RuntimeHostError>
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 delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, RuntimeHostError>
where R: GeneratedRecordAccess,
P: AsRef<[u8]> { ... }
fn emit_typed_event<E>(
&mut self,
payload: Vec<u8>,
) -> Result<(), RuntimeHostError>
where E: GeneratedEventAccess { ... }
fn for_each_record_key(
&self,
kind: RecordKind,
f: &mut dyn FnMut(RecordKey),
) -> Result<(), RuntimeHostError> { ... }
}Expand description
Typed convenience methods layered on top of the raw
RuntimeHostContext capability boundary.
Plugin authors use this extension trait directly on &mut dyn RuntimeHostContext, while host-side engine code only needs to implement the
raw object-safe methods.
Provided Methods§
Sourcefn with_read_typed<R, T, F>(
&self,
sys_id: SysId,
f: F,
) -> Result<Option<T>, RuntimeHostError>
fn with_read_typed<R, T, F>( &self, sys_id: SysId, f: F, ) -> Result<Option<T>, RuntimeHostError>
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>, RuntimeHostError>
fn with_read_typed_by_pk<R, P, T, F>( &self, pk: P, f: F, ) -> Result<Option<T>, RuntimeHostError>
Read a record by primary key without mutating it.
Prefer RuntimeHostContextExt::update_typed_by_pk when the next step
is to modify the same record. The update path keeps the mutation
in-place and avoids an extra resolve/read/then-update round-trip.
Sourcefn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, RuntimeHostError>
fn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, RuntimeHostError>
Creates a generated record.
Sourcefn update_typed_by_pk<R, P, T, F>(
&mut self,
pk: P,
f: F,
) -> Result<Option<T>, RuntimeHostError>
fn update_typed_by_pk<R, P, T, F>( &mut self, pk: P, f: F, ) -> Result<Option<T>, RuntimeHostError>
Update a record in-place by primary key.
This is the preferred hot-path API when a command needs to mutate an existing record. It avoids the read-then-update pattern that would otherwise resolve the primary key and touch the same record twice.
Sourcefn update_or_create_typed_by_pk<R, P, T, FU, FC>(
&mut self,
pk: P,
update: FU,
create: FC,
) -> Result<T, RuntimeHostError>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, RuntimeHostError>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.
Sourcefn delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, RuntimeHostError>
fn delete_by_pk<R, P>(&mut self, pk: P) -> Result<bool, RuntimeHostError>
Deletes a generated record by primary key.
Sourcefn emit_typed_event<E>(
&mut self,
payload: Vec<u8>,
) -> Result<(), RuntimeHostError>where
E: GeneratedEventAccess,
fn emit_typed_event<E>(
&mut self,
payload: Vec<u8>,
) -> Result<(), RuntimeHostError>where
E: GeneratedEventAccess,
Emits a generated event payload.
Sourcefn for_each_record_key(
&self,
kind: RecordKind,
f: &mut dyn FnMut(RecordKey),
) -> Result<(), RuntimeHostError>
fn for_each_record_key( &self, kind: RecordKind, f: &mut dyn FnMut(RecordKey), ) -> Result<(), RuntimeHostError>
Iterates record keys for one record kind.
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.