made_client/
request_context.rs1use uuid::Uuid;
2
3use crate::MadeClientError;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct RequestContext {
8 namespace: String,
9}
10
11impl RequestContext {
12 #[must_use]
13 pub fn new() -> Self {
14 Self {
15 namespace: Uuid::new_v4().to_string(),
16 }
17 }
18
19 pub fn from_id(id: impl Into<String>) -> Result<Self, MadeClientError> {
20 let id = id.into();
21 if id.trim().is_empty() || id.len() > 256 {
22 return Err(MadeClientError::InvalidInvocationId);
23 }
24 Ok(Self { namespace: id })
25 }
26
27 #[must_use]
28 pub fn id(&self) -> &str {
29 &self.namespace
30 }
31}
32
33impl Default for RequestContext {
34 fn default() -> Self {
35 Self::new()
36 }
37}