pub trait SharedMessageAppExt {
// Required method
fn add_shared_message_with<M: Message>(
&mut self,
channel: Channel,
serialize: SerializeFn<ClientSendCtx<'_>, M>,
deserialize: DeserializeFn<ServerReceiveCtx<'_>, M>,
) -> &mut Self;
// Provided methods
fn add_shared_message<M: Message + Serialize + DeserializeOwned>(
&mut self,
channel: Channel,
) -> &mut Self { ... }
fn add_mapped_shared_message<M>(&mut self, channel: Channel) -> &mut Self
where M: Message + Serialize + DeserializeOwned + MapEntities + Clone { ... }
}Expand description
An extension trait for App for creating shared messages.
They’re like client messages, but also emitted locally in the same way as on the server.
See also SharedEventAppExt for events, ClientMessageAppExt for regular client messages
and ServerMessageAppExt for server messages.
Required Methods§
Same as Self::add_shared_message, but uses the specified functions for serialization and deserialization.
Provided Methods§
Registers a remote shared message.
Similar to ClientMessageAppExt::add_client_message, but the message is emitted as
LocalOrRemote<M> both on the sender (with Sender::Local) and on the receiver
(with Sender::Remote). Useful for sharing logic between client-side prediction
and authoritative server processing.
On a listen server, locally written messages are emitted as LocalOrRemote<M> with
Sender::Local.
Calling App::add_message is not necessary. Can be used for regular messages that were
previously registered. But be careful, since all messages M are drained,
which could break Bevy or third-party plugin systems that read M.
Same as Self::add_shared_message, but additionally maps client entities to server inside the message before sending.
Always use it for messages that contain entities. Entities must be annotated with #[entities].
For details, see Component::map_entities.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".