pub struct SubnetId(/* private fields */);Expand description
Hierarchical subnet identifier.
Zero (0x00000000) means global / no subnet. Trailing zeros mean
“no sub-level specified” — SubnetId::new(&[3, 7]) represents
region=3, fleet=7, with no vehicle or subsystem restriction.
Ord is derived on the inner u32 representation. The order
has no semantic meaning for the hierarchy (it does NOT match
ancestor/descendant relationships); it exists purely as a
deterministic tiebreaker for callers that need a total order
over SubnetIds — e.g. correlation.rs::analyze_subnet_correlation
needs ties at the same depth to resolve consistently across runs
rather than depending on HashMap iteration order.
Implementations§
Source§impl SubnetId
impl SubnetId
Sourcepub const MAX_DEPTH: u8 = MAX_DEPTH
pub const MAX_DEPTH: u8 = MAX_DEPTH
Maximum hierarchy depth supported by the encoding — same
value as the module-level MAX_DEPTH constant, exposed
as an associated const so operator tooling and the SDK can
reach it through the type without an extra use.
Sourcepub fn new(levels: &[u8]) -> SubnetId
pub fn new(levels: &[u8]) -> SubnetId
Create a subnet ID from hierarchy levels (up to 4).
Levels are packed MSB-first: &[3, 7] becomes 0x03_07_00_00.
§Panics
Panics if more than 4 levels are provided. For untrusted
input (config / FFI / JSON) prefer Self::try_new.
Sourcepub fn try_new(levels: &[u8]) -> Result<SubnetId, SubnetError>
pub fn try_new(levels: &[u8]) -> Result<SubnetId, SubnetError>
Fallible variant of Self::new.
Pre-existing new panics on levels.len() > MAX_DEPTH. Returns super::SubnetError::TooManyLevels
instead so a malformed config doesn’t crash the daemon
loader.
Sourcepub const fn level(self, n: u8) -> u8
pub const fn level(self, n: u8) -> u8
Extract a specific level (0-3). Returns 0 for unset levels.
Sourcepub fn depth(self) -> u8
pub fn depth(self) -> u8
Number of non-zero hierarchy levels.
SubnetId::new(&[3, 7, 0, 0]) has depth 2.
Sourcepub fn parent(self) -> SubnetId
pub fn parent(self) -> SubnetId
Get the parent subnet (zero out the deepest non-zero level).
SubnetId::new(&[3, 7, 2]) → SubnetId::new(&[3, 7]).
SubnetId::GLOBAL → SubnetId::GLOBAL.
Sourcepub fn is_ancestor_of(self, other: SubnetId) -> bool
pub fn is_ancestor_of(self, other: SubnetId) -> bool
Check if self is an ancestor of other (prefix match).
Global is ancestor of everything. A subnet is its own ancestor.
Sourcepub const fn is_same_subnet(self, other: SubnetId) -> bool
pub const fn is_same_subnet(self, other: SubnetId) -> bool
Check if two IDs are in the same subnet (identical values).
Sourcepub fn is_sibling(self, other: SubnetId) -> bool
pub fn is_sibling(self, other: SubnetId) -> bool
Check if two IDs share the same parent.
Sourcepub const fn mask_for_depth(depth: u8) -> u32
pub const fn mask_for_depth(depth: u8) -> u32
Get the bitmask for a given depth.
depth=0 → 0x00000000 (global) depth=1 → 0xFF000000 depth=2 → 0xFFFF0000 depth=3 → 0xFFFFFF00 depth=4 → 0xFFFFFFFF
Trait Implementations§
impl Copy for SubnetId
Source§impl<'de> Deserialize<'de> for SubnetId
impl<'de> Deserialize<'de> for SubnetId
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SubnetId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SubnetId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for SubnetId
Source§impl FromStr for SubnetId
Inverse of std::fmt::Display: parses "global"
(case-insensitive) or a dotted decimal form like "3.7.2"
(each level a u8).
impl FromStr for SubnetId
Inverse of std::fmt::Display: parses "global"
(case-insensitive) or a dotted decimal form like "3.7.2"
(each level a u8).
Source§impl Ord for SubnetId
impl Ord for SubnetId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for SubnetId
impl PartialOrd for SubnetId
Source§impl Serialize for SubnetId
impl Serialize for SubnetId
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for SubnetId
Auto Trait Implementations§
impl Freeze for SubnetId
impl RefUnwindSafe for SubnetId
impl Send for SubnetId
impl Sync for SubnetId
impl Unpin for SubnetId
impl UnsafeUnpin for SubnetId
impl UnwindSafe for SubnetId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.