Struct lotus_script::message::Message  
pub struct Message { /* private fields */ }Expand description
Represents a message that can be sent between scripts or from the engine.
§Example
// Define a message type, has to implement Serialize and Deserialize
#[derive(Serialize, Deserialize)]
struct TestMessage {
    value: i32,
}
// Register the message type
message_type!(TestMessage, "test", "message");Implementations§
§impl Message
 
impl Message
pub fn new<T>(value: &T) -> Messagewhere
    T: MessageType,
pub fn new<T>(value: &T) -> Messagewhere
    T: MessageType,
Creates a new message with the given value.
pub fn meta(&self) -> &MessageMeta
pub fn meta(&self) -> &MessageMeta
Returns the message type metadata.
pub fn source(&self) -> &MessageSource
pub fn source(&self) -> &MessageSource
Returns the source of the message.
pub fn value<T>(&self) -> Result<T, MessageValueError>where
    T: MessageType,
pub fn value<T>(&self) -> Result<T, MessageValueError>where
    T: MessageType,
Returns the message value as the given type. Returns a MessageValueError if the message has a different type.
pub fn has_type<T>(&self) -> boolwhere
    T: MessageType,
pub fn has_type<T>(&self) -> boolwhere
    T: MessageType,
Returns true if the message has the given type.
pub fn handle<T>(
    &self,
    f: impl FnOnce(T) -> Result<(), Box<dyn Error>>
) -> Result<bool, MessageHandleError>where
    T: MessageType,
pub fn handle<T>(
    &self,
    f: impl FnOnce(T) -> Result<(), Box<dyn Error>>
) -> Result<bool, MessageHandleError>where
    T: MessageType,
Handle the message with the given handler function.
Returns Ok(true) if the message was handled, Ok(false) if the message has a different type,
or Err if the message could not be deserialized or the handler function returned an error.
The handler function should return Ok(()) if the message was handled successfully.
Trait Implementations§
§impl<'de> Deserialize<'de> for Message
 
impl<'de> Deserialize<'de> for Message
§fn deserialize<__D>(
    __deserializer: __D
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
    __D: Deserializer<'de>,
 
fn deserialize<__D>(
    __deserializer: __D
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
    __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl Serialize for Message
 
impl Serialize for Message
§fn serialize<__S>(
    &self,
    __serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,
 
fn serialize<__S>(
    &self,
    __serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
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