Skip to main content

ferritin_core/columns/
handles.rs

1//! Stable numeric handles for atoms, residues, and chains.
2
3macro_rules! define_handle {
4    ($(#[$doc:meta])* $name:ident) => {
5        $(#[$doc])*
6        ///
7        /// A `#[repr(transparent)]` `u32` dense row index, so it crosses an FFI or
8        /// wasm-bindgen boundary as a plain integer. It is meaningful only for the
9        /// [`TopologyColumns`](super::TopologyColumns) snapshot it came from (or any
10        /// other snapshot of the same `Arc<AtomicHierarchy>`).
11        #[repr(transparent)]
12        #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13        pub struct $name(pub u32);
14
15        impl $name {
16            /// The handle as a `usize` row index.
17            pub const fn index(self) -> usize {
18                self.0 as usize
19            }
20        }
21
22        impl From<$name> for u32 {
23            fn from(handle: $name) -> u32 {
24                handle.0
25            }
26        }
27    };
28}
29
30define_handle!(
31    /// Handle to one atom row.
32    AtomHandle
33);
34define_handle!(
35    /// Handle to one residue row.
36    ResidueHandle
37);
38define_handle!(
39    /// Handle to one chain row.
40    ChainHandle
41);