Skip to main content

wyrd/runtime_impl/
handles.rs

1//! Runtime-owned public handles around compact internal indices.
2//!
3//! Each handle carries an owner token from bind. Cross-runtime use returns
4//! [`HandleError::ForeignRuntime`](super::error::HandleError::ForeignRuntime)
5//! at the outbox and port-writer boundary instead of reading another instance's
6//! dense storage.
7
8macro_rules! runtime_handle {
9    ($name:ident, $doc:literal) => {
10        #[doc = $doc]
11        #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12        pub struct $name {
13            pub(crate) owner: usize,
14            pub(crate) index: u16,
15        }
16
17        impl $name {
18            pub(crate) const fn new(owner: usize, index: u16) -> Self {
19                Self { owner, index }
20            }
21
22            /// Return the compact per-runtime index.
23            pub const fn get(self) -> u16 {
24                self.index
25            }
26        }
27    };
28}
29
30runtime_handle!(
31    SenseId,
32    "A host-writable SignalIn handle owned by one Runtime."
33);
34runtime_handle!(
35    HostPathId,
36    "An interned SignalOut path handle owned by one Runtime."
37);
38runtime_handle!(
39    CmdId,
40    "An interned EmitCommand handle owned by one Runtime."
41);
42runtime_handle!(
43    KnotHandle,
44    "A knot handle owned by one Runtime, for checked tooling access."
45);