Skip to main content

MessageContainer

Struct MessageContainer 

Source
pub struct MessageContainer { /* private fields */ }
Expand description

A reference-counted wrapper around a heap-allocated Message trait object.

§Why Arc<Box<dyn Message>>?

broadcast_message and room_broadcast_message send the same logical message to every connected user. With a plain Box<dyn Message> this required one clone_box() call (heap allocation + copy) per user. At 1,262 CCU that is 1,262 allocations per broadcast tick.

Wrapping in Arc makes clone() a single atomic refcount increment regardless of how many users share the message. Each connection still serialises the message independently through its own entity converter — the shared data is immutable (only &self methods called on the send path).

to_boxed_any (receive path only) extracts the inner Box<dyn Message> via Arc::try_unwrap; in the rare case the Arc is still shared it falls back to clone_box(), preserving correctness without unsafe code.

Implementations§

Source§

impl MessageContainer

Source

pub fn new(message: Box<dyn Message>) -> Self

Wraps message in an Arc so it can be cheaply shared across broadcast targets.

Source

pub fn name(&self) -> String

Returns the protocol name of the contained message type.

Source

pub fn bit_length( &self, message_kinds: &MessageKinds, converter: &mut dyn LocalEntityAndGlobalEntityConverterMut, ) -> u32

Returns the serialized bit length of this message given converter for entity references.

Source

pub fn write( &self, message_kinds: &MessageKinds, writer: &mut dyn BitWrite, converter: &mut dyn LocalEntityAndGlobalEntityConverterMut, )

Writes the message’s kind tag and payload bits into writer.

Source

pub fn is_fragment(&self) -> bool

Returns true if this message is a fragment of a larger logical message.

Source

pub fn is_request_or_response(&self) -> bool

Returns true if this message envelope carries a request or response (not a plain message).

Source

pub fn to_boxed_any(self) -> Box<dyn Any>

Converts this container into a Box<dyn Any> for downcasting to the concrete message type.

Source

pub fn kind(&self) -> MessageKind

Returns the MessageKind identifying the concrete message type inside this container.

Source

pub fn relations_waiting(&self) -> Option<HashSet<RemoteEntity>>

Returns the set of remote entities this message is still waiting on, or None if ready.

Source

pub fn relations_complete( &mut self, converter: &dyn LocalEntityAndGlobalEntityConverter, )

Notifies the inner message that all awaited entity relations have been resolved.

Trait Implementations§

Source§

impl Clone for MessageContainer

Source§

fn clone(&self) -> MessageContainer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V