pub enum NodeId {
Named(String),
Hash([u8; 32]),
Blank(u64),
}Expand description
A unique identifier for a node in the graph, which can be a subject or a named object.
Nodes are the entities in the graph that are connected by relationships (predicates). A node can be identified in three ways: by a human-readable name, by a cryptographic hash, or as an anonymous blank node.
§Examples
Creating a named node:
use aingle_graph::NodeId;
let node = NodeId::named("user:alice");
assert!(node.is_named());
assert_eq!(node.as_name(), Some("user:alice"));Creating a hash-based node:
use aingle_graph::NodeId;
let hash = [0u8; 32];
let node = NodeId::hash(hash);
assert!(node.is_hash());Creating a blank node:
use aingle_graph::NodeId;
let node = NodeId::blank();
assert!(node.is_blank());Variants§
Named(String)
A named node, identified by a string, similar to a URI in RDF.
Examples: "user:alice", "org:acme", "aingle:action:abc123"
Hash([u8; 32])
A node identified by a 32-byte content hash, typically from an AIngle entry or action.
Blank(u64)
A blank (or anonymous) node, identified by a unique, auto-generated ID.
Implementations§
Source§impl NodeId
impl NodeId
Sourcepub fn named(name: impl Into<String>) -> Self
pub fn named(name: impl Into<String>) -> Self
Creates a new Named node.
§Examples
use aingle_graph::NodeId;
let node = NodeId::named("user:alice");
assert_eq!(node.as_name(), Some("user:alice"));Sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Creates a Hash-based node from a byte slice.
Sourcepub fn blank() -> Self
pub fn blank() -> Self
Creates a new, unique Blank node with an auto-incrementing ID.
Each call returns a globally unique blank node. Blank nodes are useful for representing anonymous entities in the graph.
§Examples
use aingle_graph::NodeId;
let node1 = NodeId::blank();
let node2 = NodeId::blank();
assert!(node1.is_blank());
assert!(node2.is_blank());
assert_ne!(node1, node2); // Each blank node is uniqueSourcepub fn blank_with_id(id: u64) -> Self
pub fn blank_with_id(id: u64) -> Self
Creates a Blank node with a specific ID.
Sourcepub fn namespace(&self) -> Option<&str>
pub fn namespace(&self) -> Option<&str>
For Named nodes, returns the namespace prefix (the part before the first colon).
§Examples
use aingle_graph::NodeId;
let node = NodeId::named("user:alice");
assert_eq!(node.namespace(), Some("user"));
let no_ns = NodeId::named("alice");
assert_eq!(no_ns.namespace(), Some("alice"));Sourcepub fn local_name(&self) -> Option<&str>
pub fn local_name(&self) -> Option<&str>
For Named nodes, returns the local name (the part after the last colon).
§Examples
use aingle_graph::NodeId;
let node = NodeId::named("user:alice");
assert_eq!(node.local_name(), Some("alice"));
let nested = NodeId::named("org:dept:engineering");
assert_eq!(nested.local_name(), Some("engineering"));Sourcepub fn from_storage_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_storage_bytes(bytes: &[u8]) -> Option<Self>
Deserializes a NodeId from a byte slice.