pub enum GlobalMessage {
Direct {
sender: String,
recipient: String,
content: MessageContent,
},
Broadcast {
sender: String,
topic: String,
content: MessageContent,
},
Request {
sender: String,
recipient: String,
request_id: String,
content: MessageContent,
expect_reply: bool,
},
Response {
responder: String,
request_id: String,
content: MessageContent,
},
PubSub {
publisher: String,
topic: String,
content: MessageContent,
},
}Expand description
全局消息类型
替代多处重复的 AgentMessage 定义,提供全局消息抽象。
§消息模式
Direct: 点对点直接消息Broadcast: 广播消息到所有订阅者Request: 请求消息(期待响应)Response: 响应消息PubSub: 发布-订阅模式
Variants§
Direct
点对点直接消息
Broadcast
广播消息
Request
请求消息(期待响应)
Fields
§
content: MessageContent消息内容
Response
响应消息
PubSub
发布-订阅消息
Implementations§
Source§impl GlobalMessage
impl GlobalMessage
Sourcepub fn message_type(&self) -> &'static str
pub fn message_type(&self) -> &'static str
获取消息类型标识
Sourcepub fn direct(
sender: impl Into<String>,
recipient: impl Into<String>,
content: MessageContent,
) -> GlobalMessage
pub fn direct( sender: impl Into<String>, recipient: impl Into<String>, content: MessageContent, ) -> GlobalMessage
创建点对点消息
Sourcepub fn broadcast(
sender: impl Into<String>,
topic: impl Into<String>,
content: MessageContent,
) -> GlobalMessage
pub fn broadcast( sender: impl Into<String>, topic: impl Into<String>, content: MessageContent, ) -> GlobalMessage
创建广播消息
Sourcepub fn request(
sender: impl Into<String>,
recipient: impl Into<String>,
request_id: impl Into<String>,
content: MessageContent,
) -> GlobalMessage
pub fn request( sender: impl Into<String>, recipient: impl Into<String>, request_id: impl Into<String>, content: MessageContent, ) -> GlobalMessage
创建请求消息
Sourcepub fn response(
responder: impl Into<String>,
request_id: impl Into<String>,
content: MessageContent,
) -> GlobalMessage
pub fn response( responder: impl Into<String>, request_id: impl Into<String>, content: MessageContent, ) -> GlobalMessage
创建响应消息
Trait Implementations§
Source§impl Clone for GlobalMessage
impl Clone for GlobalMessage
Source§fn clone(&self) -> GlobalMessage
fn clone(&self) -> GlobalMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for GlobalMessage
impl Debug for GlobalMessage
Source§impl<'de> Deserialize<'de> for GlobalMessage
impl<'de> Deserialize<'de> for GlobalMessage
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<GlobalMessage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<GlobalMessage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for GlobalMessage
impl Serialize for GlobalMessage
Source§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 GlobalMessage
impl RefUnwindSafe for GlobalMessage
impl Send for GlobalMessage
impl Sync for GlobalMessage
impl Unpin for GlobalMessage
impl UnsafeUnpin for GlobalMessage
impl UnwindSafe for GlobalMessage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage