pub struct Node {
pub id: NodeId,
pub kind: NodeKind,
pub span: SourceSpan,
pub children: Vec<NodeId>,
pub attributes: AttrMap,
pub(crate) content_hash: ContentHash,
pub(crate) style_id: StyleId,
}Expand description
A semantic document node (manifest §5.1).
Nodes are allocated only by Document::alloc / Document::alloc_child
from a NodeSpec: the arena assigns the NodeId and owns the
content_hash/style_id placeholders. Those two fields are pub(crate),
which makes the struct literal unconstructible outside this crate, so no
caller can fabricate a node with a fake id or a hand-set hash.
§Examples
use std::path::PathBuf;
use mos_core::{Document, NodeKind, NodeSpec, SourceSpan};
let file = PathBuf::from("main.mos");
let mut doc = Document::new(file.clone());
let id = doc.alloc(NodeSpec::new(NodeKind::Paragraph, SourceSpan::placeholder(file)));
assert_eq!(doc.get(id).map(|node| &node.kind), Some(&NodeKind::Paragraph));Fields§
§id: NodeId§kind: NodeKind§span: SourceSpan§children: Vec<NodeId>§attributes: AttrMap§content_hash: ContentHashHash-derived identity placeholder (manifest §5.1); set by the arena,
always default until the MVP 5 cache work. pub(crate) to seal
external construction.
style_id: StyleIdResolved style slot placeholder; set by the arena, always default
until styling lands. pub(crate) to seal external construction.
Implementations§
Source§impl Node
impl Node
Sourcepub const fn content_hash(&self) -> ContentHash
pub const fn content_hash(&self) -> ContentHash
The node’s content hash: a hash-derived identity placeholder (manifest §5.1), default until the MVP 5 cache work. Read-only: the arena owns this field.