1use bumpalo::{Bump, BumpAllocSafe};
3/// A node is either a text node or an element.
9 /// An element potentially with attributes and children.
10 Element(ElementNode<'a>),
13/// Text nodes are just a string of text. They cannot have attributes or
15#[derive(Debug, Clone)]
16pub struct TextNode<'a> {
17 pub(crate) text: &'a str,
20/// Elements have a tag name, zero or more attributes, and zero or more
22#[derive(Debug, Clone)]
23pub struct ElementNode<'a> {
24 pub(crate) tag_name: &'a str,
25 pub(crate) attributes: &'a [Attribute<'a>],
26 pub(crate) children: &'a [Node<'a>],
29#[derive(Clone, Debug)]
30pub struct Attribute<'a> {
36 /// Is this node a text node?
37 pub fn is_text(&self) -> bool {
39 Node::Text(_) => true,
44 /// Is this node an element?
45 pub fn is_element(&self) -> bool {
47 Node::Element { .. } => true,
53impl<'a> BumpAllocSafe for Node<'a> {}
54impl<'a> BumpAllocSafe for Attribute<'a> {}
57 /// Construct a new text node with the given text.
59 pub fn text(text: &'a str) -> Node<'a> {
60 Node::Text(TextNode { text })
63 /// Construct a new element node with the given tag name and children.
65 pub fn element<Attributes, Children>(
68 attributes: Attributes,
72 Attributes: 'a + BumpAllocSafe + AsRef<[Attribute<'a>]>,
73 Children: 'a + BumpAllocSafe + AsRef<[Node<'a>]>,
75 let children: &'a Children = bump.alloc(children);
76 let children: &'a [Node<'a>] = children.as_ref();
78 let attributes: &'a Attributes = bump.alloc(attributes);
79 let attributes: &'a [Attribute<'a>] = attributes.as_ref();
81 Node::Element(ElementNode {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list