pub struct RequestContext {
pub tx: Arc<str>,
pub client_id: Option<ClientId>,
pub lineage: Vec<Arc<str>>,
pub host_id: Uuid,
pub created_at: String,
pub windback: Option<Arc<str>>,
}Expand description
Context that propagates through request processing.
Created when a request arrives via WebSocket and flows through command execution, query subscriptions, and report generation.
Fields§
§tx: Arc<str>Transaction ID - same across all operations in one request. Used to correlate logs, events, and responses.
client_id: Option<ClientId>Client ID of the WebSocket connection that initiated this request.
None for internal operations (sagas, startup tasks).
lineage: Vec<Arc<str>>Call chain tracking the path of execution.
Starts with ["client"] for WebSocket requests or ["saga", "SagaName"] for sagas.
Extended via child() for nested operations.
host_id: UuidServer that received the original request.
created_at: StringISO timestamp when the request started.
windback: Option<Arc<str>>Windback timestamp for historical state viewing.
When set, queries should return state as of this ISO timestamp.
None means the client is viewing live state.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn new(
tx: Arc<str>,
client_id: Option<Arc<str>>,
lineage: Vec<Arc<str>>,
host_id: Uuid,
created_at: String,
) -> Self
pub fn new( tx: Arc<str>, client_id: Option<Arc<str>>, lineage: Vec<Arc<str>>, host_id: Uuid, created_at: String, ) -> Self
Create a new RequestContext with explicit values.
Sourcepub fn from_client(tx: Arc<str>, client_id: Arc<str>, host_id: Uuid) -> Self
pub fn from_client(tx: Arc<str>, client_id: Arc<str>, host_id: Uuid) -> Self
Create a context for a client-initiated request.
Sets lineage to ["client"] and created_at to current time.
Use from_client_with_windback to include windback state.
Sourcepub fn from_client_with_windback(
tx: Arc<str>,
client_id: Arc<str>,
host_id: Uuid,
windback: Option<Arc<str>>,
) -> Self
pub fn from_client_with_windback( tx: Arc<str>, client_id: Arc<str>, host_id: Uuid, windback: Option<Arc<str>>, ) -> Self
Create a context for a client-initiated request with windback state.
Sets lineage to ["client"] and created_at to current time.
Sourcepub fn internal(tx: Arc<str>, host_id: Uuid, origin: &str) -> Self
pub fn internal(tx: Arc<str>, host_id: Uuid, origin: &str) -> Self
Create a context for an internal operation (no client).
Used for saga-initiated operations, startup tasks, etc.
Sourcepub fn child(&self, operation: &str) -> Self
pub fn child(&self, operation: &str) -> Self
Create a child context with extended lineage.
Used when making sub-operations (nested commands, queries from reports, etc.) to track the call chain. Preserves the parent’s windback state.
§Example
use std::sync::Arc;
use uuid::Uuid;
use myko::request::RequestContext;
let tx: Arc<str> = "tx-1".into();
let client_id: Arc<str> = "client-1".into();
let host_id = Uuid::new_v4();
let parent = RequestContext::from_client(tx, client_id, host_id);
let child = parent.child("CreateBinding");
assert_eq!(child.lineage.len(), 2);
assert_eq!(child.lineage[0].as_ref(), "client");
assert_eq!(child.lineage[1].as_ref(), "CreateBinding");Sourcepub fn is_windback(&self) -> bool
pub fn is_windback(&self) -> bool
Check if this context is in windback mode.
Sourcepub fn lineage_string(&self) -> String
pub fn lineage_string(&self) -> String
Get the lineage as a string for logging.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RequestContext
impl RefUnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin for RequestContext
impl UnwindSafe for RequestContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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>
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>
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 more