Skip to main content

SubnetId

Struct SubnetId 

Source
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

Source

pub const GLOBAL: SubnetId

Global / no subnet.

Source

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.

Source

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.

Source

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.

Source

pub const fn from_raw(raw: u32) -> SubnetId

Create from raw u32 value.

Source

pub const fn raw(self) -> u32

Get the raw u32 value.

Source

pub const fn level(self, n: u8) -> u8

Extract a specific level (0-3). Returns 0 for unset levels.

Source

pub fn depth(self) -> u8

Number of non-zero hierarchy levels.

SubnetId::new(&[3, 7, 0, 0]) has depth 2.

Source

pub const fn is_global(self) -> bool

Check if this is the global (zero) subnet.

Source

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::GLOBALSubnetId::GLOBAL.

Source

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.

Source

pub const fn is_same_subnet(self, other: SubnetId) -> bool

Check if two IDs are in the same subnet (identical values).

Source

pub fn is_sibling(self, other: SubnetId) -> bool

Check if two IDs share the same parent.

Source

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§

Source§

impl Clone for SubnetId

Source§

fn clone(&self) -> SubnetId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SubnetId

Source§

impl Debug for SubnetId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for SubnetId

Source§

fn default() -> SubnetId

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SubnetId

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<SubnetId, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for SubnetId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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).

Source§

type Err = SubnetError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<SubnetId, <SubnetId as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for SubnetId

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for SubnetId

Source§

fn cmp(&self, other: &SubnetId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SubnetId

Source§

fn eq(&self, other: &SubnetId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SubnetId

Source§

fn partial_cmp(&self, other: &SubnetId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for SubnetId

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SubnetId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CallHasher for T
where T: Hash + ?Sized,

Source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more