Skip to main content

RuntimeHostContextExt

Trait RuntimeHostContextExt 

Source
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§

Source

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,

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>, RuntimeHostError>
where R: GeneratedRecordAccess, P: AsRef<[u8]>, F: FnOnce(R::Access<'_>) -> T,

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.

Source

fn create_typed<R, F>(&mut self, init: F) -> Result<RecordKey, RuntimeHostError>
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>, RuntimeHostError>
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 mutate 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 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.

Source

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

Deletes a generated record by primary key.

Source

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

Emits a generated event payload.

Source

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.

Implementors§