use crate::types::{ActorId, RequestId, TraceId};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ReasonCode(pub &'static str);
impl ReasonCode {
#[must_use]
pub const fn new(code: &'static str) -> Self {
Self(code)
}
}
impl std::fmt::Display for ReasonCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
pub struct SecretRef(String);
impl SecretRef {
#[must_use]
pub fn new(uri: String) -> Self {
Self(uri)
}
#[must_use]
pub fn as_uri(&self) -> &str {
&self.0
}
}
impl std::fmt::Debug for SecretRef {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SecretRef(REDACTED)")
}
}
#[must_use]
#[derive(Clone, Debug)]
pub struct CorrelationContext {
request_id: RequestId,
trace_id: Option<TraceId>,
actor_id: Option<ActorId>,
}
impl CorrelationContext {
pub fn new(request_id: RequestId) -> Self {
Self {
request_id,
trace_id: None,
actor_id: None,
}
}
pub fn with_trace(mut self, trace_id: TraceId) -> Self {
self.trace_id = Some(trace_id);
self
}
pub fn with_actor(mut self, actor_id: ActorId) -> Self {
self.actor_id = Some(actor_id);
self
}
#[must_use]
pub fn request_id(&self) -> &RequestId {
&self.request_id
}
#[must_use]
pub fn trace_id(&self) -> Option<&TraceId> {
self.trace_id.as_ref()
}
#[must_use]
pub fn actor_id(&self) -> Option<&ActorId> {
self.actor_id.as_ref()
}
}