pub struct CustomMessageRegistry { /* private fields */ }Expand description
Registry for deserializing CustomMessage types from JSON.
Each custom message type that supports serialization must register a
deserializer keyed by its CustomMessage::type_name.
Implementations§
Source§impl CustomMessageRegistry
impl CustomMessageRegistry
Sourcepub fn register(
&mut self,
type_name: impl Into<String>,
deserializer: Box<dyn Fn(Value) -> Result<Box<dyn CustomMessage>, String> + Send + Sync>,
)
pub fn register( &mut self, type_name: impl Into<String>, deserializer: Box<dyn Fn(Value) -> Result<Box<dyn CustomMessage>, String> + Send + Sync>, )
Register a deserializer for a custom message type.
The type_name must match the value returned by the corresponding
CustomMessage::type_name implementation.
Sourcepub fn register_type<T>(&mut self, type_name: impl Into<String>)where
T: CustomMessage + DeserializeOwned + 'static,
pub fn register_type<T>(&mut self, type_name: impl Into<String>)where
T: CustomMessage + DeserializeOwned + 'static,
Convenience method: register a type that implements serde::Deserialize.
Equivalent to calling register with a closure that
deserializes via serde_json::from_value.
Sourcepub fn deserialize(
&self,
type_name: &str,
value: Value,
) -> Result<Box<dyn CustomMessage>, String>
pub fn deserialize( &self, type_name: &str, value: Value, ) -> Result<Box<dyn CustomMessage>, String>
Deserialize a custom message from its type name and JSON payload.
§Errors
Returns Err if no deserializer is registered for type_name or if
deserialization fails.
Sourcepub fn has_type_name(&self, type_name: &str) -> bool
pub fn has_type_name(&self, type_name: &str) -> bool
Returns true if a deserializer is registered for type_name.
Trait Implementations§
Source§impl Debug for CustomMessageRegistry
impl Debug for CustomMessageRegistry
Auto Trait Implementations§
impl Freeze for CustomMessageRegistry
impl !RefUnwindSafe for CustomMessageRegistry
impl Send for CustomMessageRegistry
impl Sync for CustomMessageRegistry
impl Unpin for CustomMessageRegistry
impl UnsafeUnpin for CustomMessageRegistry
impl !UnwindSafe for CustomMessageRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more