moirai_core/communication/
message.rs1use std::sync::Arc;
2
3pub struct Message<T> {
5 data: Arc<T>,
7}
8
9impl<T> Message<T> {
10 pub fn new(data: T) -> Self {
12 Self {
13 data: Arc::new(data),
14 }
15 }
16
17 pub fn data(&self) -> &T {
19 &self.data
20 }
21
22 pub fn try_unwrap(self) -> Result<T, Self> {
24 Arc::try_unwrap(self.data).map_err(|data| Self { data })
25 }
26}
27
28impl<T> Clone for Message<T> {
29 fn clone(&self) -> Self {
30 Self {
31 data: Arc::clone(&self.data),
32 }
33 }
34}
35
36impl<T> std::fmt::Debug for Message<T> {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 f.debug_struct("Message")
39 .field("data", &format!("Arc<{}>", std::any::type_name::<T>()))
40 .finish()
41 }
42}