pub struct Message(/* private fields */);Expand description
A type-erased message container.
Messages can be any type that is Send + 'static. Use Message::new to create
a message and Message::downcast to retrieve the original type.
§Example
use bubbletea::Message;
struct MyMsg(i32);
let msg = Message::new(MyMsg(42));
if let Some(my_msg) = msg.downcast::<MyMsg>() {
assert_eq!(my_msg.0, 42);
}Implementations§
Source§impl Message
impl Message
Sourcepub fn new<M: Any + Send + 'static>(msg: M) -> Self
pub fn new<M: Any + Send + 'static>(msg: M) -> Self
Create a new message from any sendable type.
Sourcepub fn downcast<M: Any + Send + 'static>(self) -> Option<M>
pub fn downcast<M: Any + Send + 'static>(self) -> Option<M>
Try to downcast to a specific message type.
Returns Some(T) if the message is of type T, otherwise None.
Trait Implementations§
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