Byte Engine Docs
View on docs.rs

message_bus

Generated Rust API reference for byte_engine.

byte_engine / core / message_bus


Module message_bus

Startup-sized storage shared by the engine's typed message routes.

Create one MessageBus during application startup, then create a MessageScope for each independently owned group of channels. Message types are registered lazily the first time a channel requests them.

Quick Reference

ItemKindDescription
MessageBusConfigstructThe MessageBusConfig struct defines the fixed storage limits reserved at startup.
TopicSnapshotstructThe TopicSnapshot struct reports one typed route's current state for diagnostics.
MessageBusstructThe MessageBus struct owns one fixed heterogeneous payload arena and its lazy route registry.
MessageScopestructThe MessageScope struct isolates typed routes owned by one subsystem while sharing bus storage.
MessageBusConfigErrorenumThe MessageBusConfigError enum explains why startup storage cannot be allocated.
MessageRouteErrorenumThe MessageRouteError enum explains why a lazy typed route cannot be acquired.

Structs

MessageBusConfig

struct MessageBusConfig {
    pub max_topics: usize,
    pub cells_per_topic: usize,
    pub cell_bytes: usize,
    pub cell_alignment: usize,
    pub max_listeners_per_topic: usize,
}

Defined in crates/byte-engine/src/core/message_bus.rs:33-44

The MessageBusConfig struct defines the fixed storage limits reserved at startup.

Fields

  • max_topics: usize

    Maximum number of typed routes across every scope.

  • cells_per_topic: usize

    Number of fixed cells reserved for each typed route.

  • cell_bytes: usize

    Number of payload bytes in one cell.

  • cell_alignment: usize

    Alignment of every payload cell.

  • max_listeners_per_topic: usize

    Maximum number of simultaneous listeners on one typed route.

Implementations

  • fn new(max_topics: usize, cells_per_topic: usize, cell_bytes: usize) -> Self

    Creates fixed message storage with the supplied route and cell limits.

    Next, adjust alignment or listener limits if the application needs values

    outside the defaults, then pass the result to MessageBus::new.

  • fn with_cell_alignment(self, cell_alignment: usize) -> Self

    Returns this configuration with a replacement payload alignment.

  • fn with_max_listeners_per_topic(self, max_listeners_per_topic: usize) -> Self

    Returns this configuration with a replacement per-topic listener limit.

Trait Implementations

impl ArchivePointee for MessageBusConfig
  • type ArchivedMetadata = ()
  • fn pointer_metadata(_: &<T as ArchivePointee>::ArchivedMetadata) -> <T as Pointee>::Metadata
impl<ST> CastableFrom for MessageBusConfig
impl Clone for MessageBusConfig
impl Copy for MessageBusConfig
impl Debug for MessageBusConfig
  • fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Default for MessageBusConfig
  • fn default() -> Self
impl Downcast for MessageBusConfig
  • fn into_any(self: Box<T>) -> Box<dyn Any>
  • fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
  • fn as_any(&self) -> &dyn Any
  • fn as_any_mut(&mut self) -> &mut dyn Any
impl DowncastSend for MessageBusConfig
  • fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>
impl DowncastSync for MessageBusConfig
  • fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>
impl Eq for MessageBusConfig
impl<K> Equivalent for MessageBusConfig
  • fn equivalent(&self, key: &K) -> bool
impl Instrument for MessageBusConfig
impl LayoutRaw for MessageBusConfig
  • fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T, N1> Niching for MessageBusConfig
  • unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
  • fn resolve_niched(out: Place<NichedOption<T, N1>>)
impl PartialEq for MessageBusConfig
impl Pointable for MessageBusConfig
  • const ALIGN: usize
  • type Init = T
  • unsafe fn init(init: <T as Pointable>::Init) -> usize
  • unsafe fn deref<'a>(ptr: usize) -> &'a T
  • unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
  • unsafe fn drop(ptr: usize)
impl Pointee for MessageBusConfig
  • type Metadata = ()
impl Read for MessageBusConfig
impl<R> ReadPrimitive for MessageBusConfig
impl StructuralPartialEq for MessageBusConfig
impl WithSubscriber for MessageBusConfig

TopicSnapshot

struct TopicSnapshot {
    pub topic_id: usize,
    pub scope_id: u64,
    pub scope: std::sync::Arc<str>,
    pub message_type: &'static str,
    pub capacity: usize,
    pub active_listeners: usize,
    pub queued_for_slowest_listener: usize,
    pub published: u64,
    pub full: u64,
    pub disconnected: u64,
}

Defined in crates/byte-engine/src/core/message_bus.rs:252-263

The TopicSnapshot struct reports one typed route's current state for diagnostics.

Trait Implementations

impl ArchivePointee for TopicSnapshot
  • type ArchivedMetadata = ()
  • fn pointer_metadata(_: &<T as ArchivePointee>::ArchivedMetadata) -> <T as Pointee>::Metadata
impl<ST> CastableFrom for TopicSnapshot
impl Clone for TopicSnapshot
impl Debug for TopicSnapshot
  • fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Downcast for TopicSnapshot
  • fn into_any(self: Box<T>) -> Box<dyn Any>
  • fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
  • fn as_any(&self) -> &dyn Any
  • fn as_any_mut(&mut self) -> &mut dyn Any
impl DowncastSend for TopicSnapshot
  • fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>
impl DowncastSync for TopicSnapshot
  • fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>
impl Eq for TopicSnapshot
impl<K> Equivalent for TopicSnapshot
  • fn equivalent(&self, key: &K) -> bool
impl Instrument for TopicSnapshot
impl LayoutRaw for TopicSnapshot
  • fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T, N1> Niching for TopicSnapshot
  • unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
  • fn resolve_niched(out: Place<NichedOption<T, N1>>)
impl PartialEq for TopicSnapshot
  • fn eq(&self, other: &TopicSnapshot) -> bool

    Related: TopicSnapshot

impl Pointable for TopicSnapshot
  • const ALIGN: usize
  • type Init = T
  • unsafe fn init(init: <T as Pointable>::Init) -> usize
  • unsafe fn deref<'a>(ptr: usize) -> &'a T
  • unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
  • unsafe fn drop(ptr: usize)
impl Pointee for TopicSnapshot
  • type Metadata = ()
impl Read for TopicSnapshot
impl StructuralPartialEq for TopicSnapshot
impl WithSubscriber for TopicSnapshot

MessageBus

struct MessageBus {
    // [REDACTED: Private Fields]
}

Defined in crates/byte-engine/src/core/message_bus.rs:267-269

The MessageBus struct owns one fixed heterogeneous payload arena and its lazy route registry.

Implementations

  • fn new(config: MessageBusConfig) -> Result<Self, MessageBusConfigError>

    Related: MessageBusConfig, MessageBusConfigError

    Allocates the complete payload arena and route metadata.

    Next, call Self::new_scope for each owner that needs isolated typed

    routes, then acquire channels or factories from that scope.

  • fn config(&self) -> MessageBusConfig

    Related: MessageBusConfig

    Returns the immutable startup limits for this bus.

  • fn observe(&self) -> Result<MessageObserver, MessageObservationError>

    Related: MessageObserver, MessageObservationError

    Attaches the one passive observer for this bus.

    The observer sees successful publications from every future route,

    including application-defined generic types. Attach it before acquiring

    the first channel or factory. Publication observation reads existing route

    counters, so it never delays publishers.

  • fn new_scope(&self, name: impl Into<Arc<str>>) -> MessageScope

    Related: MessageScope

    Creates an isolated namespace over the same fixed arena.

    Routes remain lazy: creating a scope does not claim a topic until code

    requests a concrete message type from it.

  • fn topics(&self) -> Vec<TopicSnapshot>

    Related: TopicSnapshot

    Returns diagnostic snapshots for every route registered so far.

Trait Implementations

impl ArchivePointee for MessageBus
  • type ArchivedMetadata = ()
  • fn pointer_metadata(_: &<T as ArchivePointee>::ArchivedMetadata) -> <T as Pointee>::Metadata
impl<ST> CastableFrom for MessageBus
impl Clone for MessageBus
  • fn clone(&self) -> MessageBus

    Related: MessageBus

impl Default for MessageBus
  • fn default() -> Self
impl Downcast for MessageBus
  • fn into_any(self: Box<T>) -> Box<dyn Any>
  • fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
  • fn as_any(&self) -> &dyn Any
  • fn as_any_mut(&mut self) -> &mut dyn Any
impl DowncastSend for MessageBus
  • fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>
impl DowncastSync for MessageBus
  • fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>
impl Instrument for MessageBus
impl LayoutRaw for MessageBus
  • fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T, N1> Niching for MessageBus
  • unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
  • fn resolve_niched(out: Place<NichedOption<T, N1>>)
impl Pointable for MessageBus
  • const ALIGN: usize
  • type Init = T
  • unsafe fn init(init: <T as Pointable>::Init) -> usize
  • unsafe fn deref<'a>(ptr: usize) -> &'a T
  • unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
  • unsafe fn drop(ptr: usize)
impl Pointee for MessageBus
  • type Metadata = ()
impl Read for MessageBus
impl<R> ReadPrimitive for MessageBus
impl WithSubscriber for MessageBus

MessageScope

struct MessageScope {
    // [REDACTED: Private Fields]
}

Defined in crates/byte-engine/src/core/message_bus.rs:382-386

The MessageScope struct isolates typed routes owned by one subsystem while sharing bus storage.

Implementations

  • fn channel<M>(&self) -> DefaultChannel<M>

    Acquires the canonical typed channel in this scope, registering it on first use.

    Next, create listeners before publishing messages that they must observe.

  • fn try_channel<M>(&self) -> Result<DefaultChannel<M>, MessageRouteError>

    Related: MessageRouteError

    Tries to acquire the canonical typed channel in this scope.

  • fn factory<T>(&self) -> Factory<T>

    Acquires the canonical creation factory for T in this scope.

    The factory registers CreateMessage<T> only when this method is first

    called, so application-defined types require no startup declaration.

  • fn name(&self) -> &str

    Returns this scope's diagnostic name.

  • fn topics(&self) -> Vec<TopicSnapshot>

    Related: TopicSnapshot

    Returns diagnostic snapshots for routes registered in this scope.

Trait Implementations

impl ArchivePointee for MessageScope
  • type ArchivedMetadata = ()
  • fn pointer_metadata(_: &<T as ArchivePointee>::ArchivedMetadata) -> <T as Pointee>::Metadata
impl<ST> CastableFrom for MessageScope
impl Clone for MessageScope
impl Debug for MessageScope
  • fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result
impl Downcast for MessageScope
  • fn into_any(self: Box<T>) -> Box<dyn Any>
  • fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
  • fn as_any(&self) -> &dyn Any
  • fn as_any_mut(&mut self) -> &mut dyn Any
impl DowncastSend for MessageScope
  • fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>
impl DowncastSync for MessageScope
  • fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>
impl Instrument for MessageScope
impl LayoutRaw for MessageScope
  • fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T, N1> Niching for MessageScope
  • unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
  • fn resolve_niched(out: Place<NichedOption<T, N1>>)
impl Pointable for MessageScope
  • const ALIGN: usize
  • type Init = T
  • unsafe fn init(init: <T as Pointable>::Init) -> usize
  • unsafe fn deref<'a>(ptr: usize) -> &'a T
  • unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
  • unsafe fn drop(ptr: usize)
impl Pointee for MessageScope
  • type Metadata = ()
impl Read for MessageScope
impl WithSubscriber for MessageScope

Enums

MessageBusConfigError

enum MessageBusConfigError {
    ZeroLimit(&'static str),
    InvalidAlignment(usize),
    MisalignedCellSize {
        cell_bytes: usize,
        cell_alignment: usize,
    },
    StorageSizeOverflow,
}

Defined in crates/byte-engine/src/core/message_bus.rs:148-157

The MessageBusConfigError enum explains why startup storage cannot be allocated.

Variants

  • ZeroLimit

    A required limit was zero.

  • InvalidAlignment

    The configured cell alignment was not a nonzero power of two.

  • MisalignedCellSize

    The cell size was not a multiple of its alignment.

  • StorageSizeOverflow

    The requested arena size exceeded addressable memory.

Trait Implementations

impl ArchivePointee for MessageBusConfigError
  • type ArchivedMetadata = ()
  • fn pointer_metadata(_: &<T as ArchivePointee>::ArchivedMetadata) -> <T as Pointee>::Metadata
impl<ST> CastableFrom for MessageBusConfigError
impl Clone for MessageBusConfigError
impl Debug for MessageBusConfigError
  • fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Display for MessageBusConfigError
  • fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result
impl Downcast for MessageBusConfigError
  • fn into_any(self: Box<T>) -> Box<dyn Any>
  • fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
  • fn as_any(&self) -> &dyn Any
  • fn as_any_mut(&mut self) -> &mut dyn Any
impl DowncastSend for MessageBusConfigError
  • fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>
impl DowncastSync for MessageBusConfigError
  • fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>
impl Eq for MessageBusConfigError
impl<K> Equivalent for MessageBusConfigError
  • fn equivalent(&self, key: &K) -> bool
impl Error for MessageBusConfigError
impl Instrument for MessageBusConfigError
impl LayoutRaw for MessageBusConfigError
  • fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T, N1> Niching for MessageBusConfigError
  • unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
  • fn resolve_niched(out: Place<NichedOption<T, N1>>)
impl PartialEq for MessageBusConfigError
impl Pointable for MessageBusConfigError
  • const ALIGN: usize
  • type Init = T
  • unsafe fn init(init: <T as Pointable>::Init) -> usize
  • unsafe fn deref<'a>(ptr: usize) -> &'a T
  • unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
  • unsafe fn drop(ptr: usize)
impl Pointee for MessageBusConfigError
  • type Metadata = ()
impl Read for MessageBusConfigError
impl StructuralPartialEq for MessageBusConfigError
impl ToString for MessageBusConfigError
  • fn to_string(&self) -> String
impl WithSubscriber for MessageBusConfigError

MessageRouteError

enum MessageRouteError {
    TopicLimit {
        message_type: &'static str,
        max_topics: usize,
    },
    MessageTooLarge {
        message_type: &'static str,
        message_bytes: usize,
        available_bytes: usize,
    },
    MessageOveraligned {
        message_type: &'static str,
        required_alignment: usize,
        cell_alignment: usize,
    },
    ListenerLimit {
        message_type: &'static str,
        max_listeners: usize,
    },
}

Defined in crates/byte-engine/src/core/message_bus.rs:189-209

The MessageRouteError enum explains why a lazy typed route cannot be acquired.

Variants

  • TopicLimit

    The bus has no unclaimed topic slab.

  • MessageTooLarge

    One message cannot fit in its topic slab.

  • MessageOveraligned

    The message requires stricter alignment than the arena provides.

  • ListenerLimit

    The route has no free listener descriptor.

Trait Implementations

impl ArchivePointee for MessageRouteError
  • type ArchivedMetadata = ()
  • fn pointer_metadata(_: &<T as ArchivePointee>::ArchivedMetadata) -> <T as Pointee>::Metadata
impl<ST> CastableFrom for MessageRouteError
impl Clone for MessageRouteError
impl Debug for MessageRouteError
  • fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Display for MessageRouteError
  • fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result
impl Downcast for MessageRouteError
  • fn into_any(self: Box<T>) -> Box<dyn Any>
  • fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
  • fn as_any(&self) -> &dyn Any
  • fn as_any_mut(&mut self) -> &mut dyn Any
impl DowncastSend for MessageRouteError
  • fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>
impl DowncastSync for MessageRouteError
  • fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>
impl Eq for MessageRouteError
impl<K> Equivalent for MessageRouteError
  • fn equivalent(&self, key: &K) -> bool
impl Error for MessageRouteError
impl Instrument for MessageRouteError
impl LayoutRaw for MessageRouteError
  • fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T, N1> Niching for MessageRouteError
  • unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
  • fn resolve_niched(out: Place<NichedOption<T, N1>>)
impl PartialEq for MessageRouteError
impl Pointable for MessageRouteError
  • const ALIGN: usize
  • type Init = T
  • unsafe fn init(init: <T as Pointable>::Init) -> usize
  • unsafe fn deref<'a>(ptr: usize) -> &'a T
  • unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
  • unsafe fn drop(ptr: usize)
impl Pointee for MessageRouteError
  • type Metadata = ()
impl Read for MessageRouteError
impl StructuralPartialEq for MessageRouteError
impl ToString for MessageRouteError
  • fn to_string(&self) -> String
impl WithSubscriber for MessageRouteError

On this page

Module message_busQuick ReferenceStructsMessageBusConfigFieldsImplementationsTrait Implementationsimpl ArchivePointee for MessageBusConfigimpl<ST> CastableFrom for MessageBusConfigimpl Clone for MessageBusConfigimpl Copy for MessageBusConfigimpl Debug for MessageBusConfigimpl Default for MessageBusConfigimpl Downcast for MessageBusConfigimpl DowncastSend for MessageBusConfigimpl DowncastSync for MessageBusConfigimpl Eq for MessageBusConfigimpl<K> Equivalent for MessageBusConfigimpl Instrument for MessageBusConfigimpl LayoutRaw for MessageBusConfigimpl<T, N1> Niching for MessageBusConfigimpl PartialEq for MessageBusConfigimpl Pointable for MessageBusConfigimpl Pointee for MessageBusConfigimpl Read for MessageBusConfigimpl<R> ReadPrimitive for MessageBusConfigimpl StructuralPartialEq for MessageBusConfigimpl WithSubscriber for MessageBusConfigTopicSnapshotTrait Implementationsimpl ArchivePointee for TopicSnapshotimpl<ST> CastableFrom for TopicSnapshotimpl Clone for TopicSnapshotimpl Debug for TopicSnapshotimpl Downcast for TopicSnapshotimpl DowncastSend for TopicSnapshotimpl DowncastSync for TopicSnapshotimpl Eq for TopicSnapshotimpl<K> Equivalent for TopicSnapshotimpl Instrument for TopicSnapshotimpl LayoutRaw for TopicSnapshotimpl<T, N1> Niching for TopicSnapshotimpl PartialEq for TopicSnapshotimpl Pointable for TopicSnapshotimpl Pointee for TopicSnapshotimpl Read for TopicSnapshotimpl StructuralPartialEq for TopicSnapshotimpl WithSubscriber for TopicSnapshotMessageBusImplementationsTrait Implementationsimpl ArchivePointee for MessageBusimpl<ST> CastableFrom for MessageBusimpl Clone for MessageBusimpl Default for MessageBusimpl Downcast for MessageBusimpl DowncastSend for MessageBusimpl DowncastSync for MessageBusimpl Instrument for MessageBusimpl LayoutRaw for MessageBusimpl<T, N1> Niching for MessageBusimpl Pointable for MessageBusimpl Pointee for MessageBusimpl Read for MessageBusimpl<R> ReadPrimitive for MessageBusimpl WithSubscriber for MessageBusMessageScopeImplementationsTrait Implementationsimpl ArchivePointee for MessageScopeimpl<ST> CastableFrom for MessageScopeimpl Clone for MessageScopeimpl Debug for MessageScopeimpl Downcast for MessageScopeimpl DowncastSend for MessageScopeimpl DowncastSync for MessageScopeimpl Instrument for MessageScopeimpl LayoutRaw for MessageScopeimpl<T, N1> Niching for MessageScopeimpl Pointable for MessageScopeimpl Pointee for MessageScopeimpl Read for MessageScopeimpl WithSubscriber for MessageScopeEnumsMessageBusConfigErrorVariantsTrait Implementationsimpl ArchivePointee for MessageBusConfigErrorimpl<ST> CastableFrom for MessageBusConfigErrorimpl Clone for MessageBusConfigErrorimpl Debug for MessageBusConfigErrorimpl Display for MessageBusConfigErrorimpl Downcast for MessageBusConfigErrorimpl DowncastSend for MessageBusConfigErrorimpl DowncastSync for MessageBusConfigErrorimpl Eq for MessageBusConfigErrorimpl<K> Equivalent for MessageBusConfigErrorimpl Error for MessageBusConfigErrorimpl Instrument for MessageBusConfigErrorimpl LayoutRaw for MessageBusConfigErrorimpl<T, N1> Niching for MessageBusConfigErrorimpl PartialEq for MessageBusConfigErrorimpl Pointable for MessageBusConfigErrorimpl Pointee for MessageBusConfigErrorimpl Read for MessageBusConfigErrorimpl StructuralPartialEq for MessageBusConfigErrorimpl ToString for MessageBusConfigErrorimpl WithSubscriber for MessageBusConfigErrorMessageRouteErrorVariantsTrait Implementationsimpl ArchivePointee for MessageRouteErrorimpl<ST> CastableFrom for MessageRouteErrorimpl Clone for MessageRouteErrorimpl Debug for MessageRouteErrorimpl Display for MessageRouteErrorimpl Downcast for MessageRouteErrorimpl DowncastSend for MessageRouteErrorimpl DowncastSync for MessageRouteErrorimpl Eq for MessageRouteErrorimpl<K> Equivalent for MessageRouteErrorimpl Error for MessageRouteErrorimpl Instrument for MessageRouteErrorimpl LayoutRaw for MessageRouteErrorimpl<T, N1> Niching for MessageRouteErrorimpl PartialEq for MessageRouteErrorimpl Pointable for MessageRouteErrorimpl Pointee for MessageRouteErrorimpl Read for MessageRouteErrorimpl StructuralPartialEq for MessageRouteErrorimpl ToString for MessageRouteErrorimpl WithSubscriber for MessageRouteError