Skip to main content

CustomMessage

Trait CustomMessage 

Source
pub trait CustomMessage:
    Send
    + Sync
    + Debug
    + Any {
    // Required method
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn type_name(&self) -> Option<&str> { ... }
    fn to_json(&self) -> Option<Value> { ... }
    fn clone_box(&self) -> Option<Box<dyn CustomMessage>> { ... }
}
Expand description

Trait for application-defined custom message types.

Allows downstream code to attach application-specific message types (e.g. notifications, artifacts) to the message history without modifying the harness.

§Serialization

To support store/load of conversations containing custom messages, implement type_name and to_json, then register a deserializer with CustomMessageRegistry.

Required Methods§

Source

fn as_any(&self) -> &dyn Any

Downcast helper. Returns self as &dyn Any for type-safe downcasting.

Provided Methods§

Source

fn type_name(&self) -> Option<&str>

A unique, stable identifier for this custom message type.

Used as the discriminator when serializing. Must match the key registered in CustomMessageRegistry. Returns None if serialization is not supported.

Source

fn to_json(&self) -> Option<Value>

Serialize this custom message to a JSON value.

Returns None if serialization is not supported (the default).

Source

fn clone_box(&self) -> Option<Box<dyn CustomMessage>>

Clone this custom message into a new boxed trait object.

Returns None if the underlying type does not support cloning (the default). Implement this to preserve custom messages across stream-driven state rebuilds (e.g. handle_stream_event).

Implementors§