pub trait RuntimeComponent:
MaybeSend
+ MaybeSync
+ 'static {
// Required methods
fn id(&self) -> ComponentId;
fn component_type(&self) -> ComponentType;
fn apply_update_payload(
&self,
payload: &[u8],
prior: Option<&[u8]>,
) -> Result<Vec<u8>, ComponentTypedError>;
fn expand_to_changes(
&self,
op: &AppDataUpdateOperation,
prior: Option<&[u8]>,
) -> Result<Vec<ExpandedComponentChange>, ComponentTypedError>;
// Provided method
fn validate_invariant(
&self,
_change: &ComponentChange<'_>,
_registry: &ComponentRegistry,
) -> Result<(), ComponentInvariantError> { ... }
}Expand description
A host-defined component whose ComponentId is known at runtime.
Unlike super::typed::Component, RuntimeComponent takes
&self and reports its id via Self::id so a single impl can
service multiple distinct ids (or build them dynamically). The
trait is otherwise structurally identical to Component minus
the typed Value / Mutation associated types — runtime
components handle bytes only, since the host owns whatever
further decoding it does on top.
The bounds are MaybeSend + MaybeSync rather than Send + Sync so that WASM hosts can register impls that hold non-Send
state (e.g. JS-bound objects). On native targets these expand to
Send + Sync and the trait behaves identically to before; on
wasm32 they expand to vacuous bounds. The dispatch path’s static
storage requirements are bridged in [RuntimeAdapter] below — see
the SAFETY note there.
Required Methods§
Sourcefn id(&self) -> ComponentId
fn id(&self) -> ComponentId
The component this instance handles.
Sourcefn component_type(&self) -> ComponentType
fn component_type(&self) -> ComponentType
Logical wire type, written into the registry entry’s
ComponentMetadata.component_type slot. The host typically
picks one of the existing ComponentType variants
(Bytes, String, TlsSetInboxId, etc.) — runtime
components are not currently expected to introduce new
ComponentTypes.
Sourcefn apply_update_payload(
&self,
payload: &[u8],
prior: Option<&[u8]>,
) -> Result<Vec<u8>, ComponentTypedError>
fn apply_update_payload( &self, payload: &[u8], prior: Option<&[u8]>, ) -> Result<Vec<u8>, ComponentTypedError>
Apply an AppDataUpdateOperation::Update payload against the
prior bytes (if any) and produce the new full-state bytes.
Sourcefn expand_to_changes(
&self,
op: &AppDataUpdateOperation,
prior: Option<&[u8]>,
) -> Result<Vec<ExpandedComponentChange>, ComponentTypedError>
fn expand_to_changes( &self, op: &AppDataUpdateOperation, prior: Option<&[u8]>, ) -> Result<Vec<ExpandedComponentChange>, ComponentTypedError>
Expand an AppDataUpdate proposal into per-element changes
for the validator’s policy loop.
Provided Methods§
Sourcefn validate_invariant(
&self,
_change: &ComponentChange<'_>,
_registry: &ComponentRegistry,
) -> Result<(), ComponentInvariantError>
fn validate_invariant( &self, _change: &ComponentChange<'_>, _registry: &ComponentRegistry, ) -> Result<(), ComponentInvariantError>
Optional component-local invariant check. Default no-op.