Skip to main content

roam_types/
requests.rs

1use facet::Facet;
2
3// r[impl connection]
4// r[impl connection.root]
5declare_id!(
6    /// Connection ID identifying a virtual connection on a link.
7    ///
8    /// Connection 0 is the root connection, established implicitly when the link is created.
9    /// Additional connections are opened via Connect/Accept messages.
10    ConnectionId, u64
11);
12
13impl ConnectionId {
14    /// The root connection (always exists on a link).
15    pub const ROOT: Self = Self(0);
16
17    /// Check if this is the root connection.
18    pub const fn is_root(self) -> bool {
19        self.0 == Self::ROOT.0
20    }
21}
22
23declare_id!(
24    /// Request ID identifying an in-flight RPC request.
25    ///
26    /// Request IDs are unique within a connection and monotonically increasing.
27    RequestId, u64
28);
29
30declare_id!(
31    /// ID of a channel between two peers.
32    ChannelId, u64
33);
34
35impl ChannelId {
36    /// Reserved channel ID (not usable).
37    pub const RESERVED: Self = Self(0);
38
39    /// Create a new channel ID, returning None if the value is 0 (reserved).
40    #[inline]
41    pub fn new(value: u64) -> Option<Self> {
42        if value == 0 { None } else { Some(Self(value)) }
43    }
44}