pub struct NodeId(/* private fields */);Expand description
A content-addressed 128-bit node identity.
NodeId is the primary key used throughout the Fission pipeline to refer to a
specific node. Because it is derived from BLAKE3 hashes, two nodes with the same
derivation inputs always produce the same NodeId, which makes tree diffing cheap.
§Construction
use fission_ir::NodeId;
// From a stable string key (good for well-known, named nodes):
let id = NodeId::explicit("sidebar");
// From a parent ID and a position path (good for list items):
let parent = NodeId::explicit("list");
let item_3 = NodeId::derived(parent.as_u128(), &[3]);§Equality and hashing
NodeId implements Eq, Hash, and Ord, so it can be used as a key in
HashMap, BTreeMap, and HashSet.
Implementations§
Source§impl NodeId
impl NodeId
Sourcepub const fn from_u128(val: u128) -> Self
pub const fn from_u128(val: u128) -> Self
Creates a NodeId from a raw 128-bit value.
This is intended for internal use or deserialization. In most cases you
should use NodeId::explicit or NodeId::derived instead.
Sourcepub fn as_u128(&self) -> u128
pub fn as_u128(&self) -> u128
Returns the underlying 128-bit value.
Useful when you need to feed a node’s identity into another hash (e.g.,
when deriving child IDs with NodeId::derived).
Sourcepub fn explicit(key: &str) -> Self
pub fn explicit(key: &str) -> Self
Creates a NodeId from a user-provided string key.
The key is hashed with BLAKE3 (prefixed with "explicit:"), producing a
deterministic ID that is stable across rebuilds as long as the key string
does not change. Use this for well-known, named nodes like "root" or
"toolbar".
§Example
use fission_ir::NodeId;
let a = NodeId::explicit("header");
let b = NodeId::explicit("header");
assert_eq!(a, b); // same key -> same IDSourcepub fn derived(parent: u128, path: &[u32]) -> Self
pub fn derived(parent: u128, path: &[u32]) -> Self
Creates a NodeId derived from a parent ID and a child-index path.
This implements structural identity: a node’s ID is determined by its position in the tree rather than by a user-provided name. Useful for dynamically generated children like list items.
§Arguments
parent– The parent node’s rawu128value (seeNodeId::as_u128).path– One or more child indices describing the path from the parent.
§Example
use fission_ir::NodeId;
let parent = NodeId::explicit("list");
let item_0 = NodeId::derived(parent.as_u128(), &[0]);
let item_1 = NodeId::derived(parent.as_u128(), &[1]);
assert_ne!(item_0, item_1);