Skip to main content

arin_protocol/
ids.rs

1//! Opaque identifiers.
2//!
3//! Both are opaque strings on the wire. Clients must not parse or construct them. The
4//! daemon is free to change the generation scheme without a protocol bump.
5
6use serde::{Deserialize, Serialize};
7
8macro_rules! opaque_id {
9    ($(#[$m:meta])* $name:ident) => {
10        $(#[$m])*
11        #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
12        #[serde(transparent)]
13        pub struct $name(pub String);
14
15        impl $name {
16            /// Wrap an existing identifier.
17            pub fn new(value: impl Into<String>) -> Self {
18                Self(value.into())
19            }
20
21            /// Borrow the underlying string.
22            pub fn as_str(&self) -> &str {
23                &self.0
24            }
25        }
26
27        impl std::fmt::Display for $name {
28            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29                f.write_str(&self.0)
30            }
31        }
32    };
33}
34
35opaque_id! {
36    /// Identifies a client session. Annotations are scoped to one.
37    SessionId
38}
39
40opaque_id! {
41    /// Identifies a single annotation within a session.
42    AnnotationId
43}