Skip to main content

Component

Trait Component 

Source
pub trait Component:
    Send
    + Sync
    + 'static {
    type Value;
    type Mutation;

    const ID: ComponentId;
    const COMPONENT_TYPE: ComponentType;

    // Required methods
    fn decode_value(bytes: &[u8]) -> Result<Self::Value, ComponentTypedError>;
    fn encode_value(value: &Self::Value) -> Result<Vec<u8>, ComponentTypedError>;
    fn encode_mutation(
        mutation: &Self::Mutation,
    ) -> Result<Vec<u8>, ComponentTypedError>;
    fn apply_update_payload(
        payload: &[u8],
        prior: Option<&[u8]>,
    ) -> Result<Vec<u8>, ComponentTypedError>;
    fn expand_to_changes(
        op: &AppDataUpdateOperation,
        prior: Option<&[u8]>,
    ) -> Result<Vec<ExpandedComponentChange>, ComponentTypedError>;

    // Provided method
    fn validate_invariant(
        _change: &ComponentChange<'_>,
        _registry: &ComponentRegistry,
    ) -> Result<(), ComponentInvariantError> { ... }
}
Expand description

A typed view of a well-known AppData component.

One impl per ComponentId — pairs the wire identifier with the component’s logical type, decode/encode round-trip, mutation serialization, in-place apply behavior for incoming Update payloads, and (optionally) component-local invariant checks.

The registry’s permission check (validate_component_write in app_data::validation) is cross-cutting and runs outside this trait. Component::validate_invariant is for component-LOCAL invariants (e.g. “GROUP_NAME ≤ 1 KiB”, “ADMIN_LIST always has at least one super-admin mirror”) that the policy evaluator can’t express.

Required Associated Constants§

Source

const ID: ComponentId

Stable wire identifier. Const-known so registries can build static lookup tables.

Source

const COMPONENT_TYPE: ComponentType

Logical wire type, written into the registry’s ComponentMetadata.component_type slot at bootstrap.

Required Associated Types§

Source

type Value

Decoded full-state value (e.g. String, TlsSet<InboxId>, TlsMap<InboxId, VLBytes>).

Source

type Mutation

Decoded payload that goes inside an AppDataUpdateOperation::Update.

For Bytes/String components this is the same as Value (a full-value replacement). For collection components this is the wire-level delta (TlsSetDelta<K> / TlsMapDelta<K, V>) carrying one or more mutations — every mutation in the delta lands as one atomic change at the receiver. Single-mutation callers build a one-element delta via the fluent builder (TlsSetDelta::new().insert(x)).

Batching matters for components like GROUP_MEMBERSHIP where all installation changes for an inbox (additions, removals, new installations) must travel in a single proposal so the receiver applies them atomically.

Required Methods§

Source

fn decode_value(bytes: &[u8]) -> Result<Self::Value, ComponentTypedError>

Decode the component’s stored bytes (as found in the AppData dictionary) into the typed value.

Source

fn encode_value(value: &Self::Value) -> Result<Vec<u8>, ComponentTypedError>

Encode a typed value back to the bytes that go in the AppData dictionary slot. The inverse of Component::decode_value.

Source

fn encode_mutation( mutation: &Self::Mutation, ) -> Result<Vec<u8>, ComponentTypedError>

Encode a Self::Mutation as the bytes that go inside an AppDataUpdateOperation::Update payload.

Bytes/String components pass through; collection components serialize the delta (which may carry multiple mutations — see the Self::Mutation doc on batching).

Source

fn apply_update_payload( payload: &[u8], prior: Option<&[u8]>, ) -> Result<Vec<u8>, ComponentTypedError>

Apply an AppDataUpdateOperation::Update payload against the component’s prior bytes (or None if first write) and return the new full bytes.

Bytes/String components ignore prior and pass through; collection components decode payload as a delta and apply it to the decoded prior set/map.

Source

fn expand_to_changes( op: &AppDataUpdateOperation, prior: Option<&[u8]>, ) -> Result<Vec<ExpandedComponentChange>, ComponentTypedError>

Expand an AppDataUpdate proposal (Update or Remove) into the per-element changes the validator’s policy loop iterates over.

Bytes components produce exactly one entry; collection components produce one entry per delta mutation.

Provided Methods§

Source

fn validate_invariant( _change: &ComponentChange<'_>, _registry: &ComponentRegistry, ) -> Result<(), ComponentInvariantError>

Optional component-local invariant check that runs after validate_component_write’s policy verdict. Default is no-op — components with no extra invariants don’t override.

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 Component for AdminListComponent

Source§

const ID: ComponentId = ComponentId::ADMIN_LIST

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::TlsSetInboxId

Source§

type Value = TlsSet<InboxId>

Source§

type Mutation = TlsSetDelta<InboxId>

Source§

impl Component for DmMembersComponent

Source§

const ID: ComponentId = ComponentId::DM_MEMBERS

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::TlsSetInboxId

Source§

type Value = TlsSet<InboxId>

Source§

type Mutation = TlsSetDelta<InboxId>

Source§

impl Component for SuperAdminListComponent

Source§

const ID: ComponentId = ComponentId::SUPER_ADMIN_LIST

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::TlsSetInboxId

Source§

type Value = TlsSet<InboxId>

Source§

type Mutation = TlsSetDelta<InboxId>

Source§

impl Component for AppDataComponent

Source§

const ID: ComponentId = ComponentId::APP_DATA

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::String

Source§

type Value = String

Source§

type Mutation = String

Source§

impl Component for CommitLogSignerComponent

Source§

const ID: ComponentId = ComponentId::COMMIT_LOG_SIGNER

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::Bytes

Source§

type Value = SecretVLBytes

Source§

type Mutation = SecretVLBytes

Source§

impl Component for GroupDescriptionComponent

Source§

const ID: ComponentId = ComponentId::GROUP_DESCRIPTION

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::String

Source§

type Value = String

Source§

type Mutation = String

Source§

impl Component for GroupImageUrlComponent

Source§

const ID: ComponentId = ComponentId::GROUP_IMAGE_URL

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::String

Source§

type Value = String

Source§

type Mutation = String

Source§

impl Component for GroupNameComponent

Source§

const ID: ComponentId = ComponentId::GROUP_NAME

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::String

Source§

type Value = String

Source§

type Mutation = String

Source§

impl Component for MessageDisappearFromNsComponent

Source§

const ID: ComponentId = ComponentId::MESSAGE_DISAPPEAR_FROM_NS

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::Bytes

Source§

type Value = i64

Source§

type Mutation = i64

Source§

impl Component for MessageDisappearInNsComponent

Source§

const ID: ComponentId = ComponentId::MESSAGE_DISAPPEAR_IN_NS

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::Bytes

Source§

type Value = i64

Source§

type Mutation = i64

Source§

impl Component for MinSupportedProtocolVersionComponent

Source§

const ID: ComponentId = ComponentId::MIN_SUPPORTED_PROTOCOL_VERSION

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::String

Source§

type Value = String

Source§

type Mutation = String

Source§

impl Component for ComponentRegistryComponent

Source§

const ID: ComponentId = ComponentId::COMPONENT_REGISTRY

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::TlsMapBytesBytes

Source§

type Value = TlsMap<ComponentId, VLBytes>

Source§

type Mutation = TlsMapDelta<ComponentId, VLBytes>

Source§

impl Component for GroupMembershipComponent

Source§

const ID: ComponentId = ComponentId::GROUP_MEMBERSHIP

Source§

const COMPONENT_TYPE: ComponentType = ComponentType::TlsMapInboxIdBytes

Source§

type Value = TlsMap<InboxId, VLBytes>

Source§

type Mutation = TlsMapDelta<InboxId, VLBytes>