pub struct Envelope<T: Serialize> {
pub source: String,
pub target: String,
pub payload: T,
pub correlation_id: Option<String>,
}Expand description
A typed message envelope for cross-machine communication.
Envelope wraps a payload of type T with routing metadata
(source, target) and an optional correlation_id for
request-response patterns. It is serializable so it can be
transmitted across process or network boundaries.
§Examples
use gust_runtime::prelude::*;
let envelope = Envelope::new("order-service", "payment-service", 42u64)
.with_correlation("req-001");
assert_eq!(envelope.source, "order-service");
assert_eq!(envelope.target, "payment-service");
assert_eq!(envelope.payload, 42u64);
assert_eq!(envelope.correlation_id.as_deref(), Some("req-001"));Fields§
§source: StringThe identifier of the sending machine or service.
target: StringThe identifier of the intended recipient machine or service.
payload: TThe message payload.
correlation_id: Option<String>An optional correlation identifier for matching requests to responses.
Implementations§
Source§impl<T: Serialize> Envelope<T>
impl<T: Serialize> Envelope<T>
Sourcepub fn new(
source: impl Into<String>,
target: impl Into<String>,
payload: T,
) -> Self
pub fn new( source: impl Into<String>, target: impl Into<String>, payload: T, ) -> Self
Creates a new envelope with the given source, target, and payload.
The correlation_id is initially None. Use
with_correlation to set it.
Sourcepub fn with_correlation(self, id: impl Into<String>) -> Self
pub fn with_correlation(self, id: impl Into<String>) -> Self
Sets the correlation identifier on this envelope (builder pattern).
Correlation IDs are useful for matching asynchronous responses back to the original request.