Struct figtree::types::Document
[−]
[src]
pub struct Document { /* fields omitted */ }
A struct representing a parsed figtree document.
Examples
use figtree::types::*; let mut doc = Document::new(); assert!(doc.is_empty()); doc.new_node_or_get("node name"); assert!(doc.node_count() == 1); { // appease the borrow checker by scoping this off // in real code this would be unnecessary because there is no need to do // something so pathological. let node = doc.get_node("node name").expect("no such node"); assert!(node == &Node::new()); // new node is a fresh, blank node } { // again, appease the borrow checker let mut node = doc.get_node_mut("node name").expect("no such node"); // node can be modified here }
Methods
impl Document
[src]
fn new() -> Self
Construct a new, empty document
fn new_node_or_get<S>(&mut self, name: S) -> &mut Node where
S: Into<String>,
S: Into<String>,
Construct a new node and insert it into the document.
Returns a mutable reference to the new node. If there is a node already present with the given name, this method will not insert a new node and instead just return the old node.
fn insert_node<S>(&mut self, name: S, node: Node) -> Option<Node> where
S: Into<String>,
S: Into<String>,
Inserts a node into the document.
If there is already a node with the given name, replace it and return the old node.
fn delete_node<S>(&mut self, name: S) -> Option<Node> where
S: Into<String>,
S: Into<String>,
Remove a node from the document.
Returns the deleted node, if it exists.
fn get_node<S>(&self, name: S) -> Option<&Node> where
S: Into<String>,
S: Into<String>,
Get a reference to a specified node
Essentially a thin wrapper around the Document.nodes
mapping, but it allows for
&str arguments, and allows users to do common operations without having to know
about the internal structure of the node.
fn get_node_mut<S>(&mut self, name: S) -> Option<&mut Node> where
S: Into<String>,
S: Into<String>,
Get a mutable reference to a specified node
Essentially a thin wrapper around the Document.nodes
mapping, but it allows for
&str arguments, and allows users to do common operations without having to know
about the internal structure of the node.
fn iter_nodes(&self) -> Iter<String, Node>
Get an iterable of (&name, &node) pairs
fn is_empty(&self) -> bool
Test if the document is empty - if it has no nodes.
fn has_node(&self, name: &String) -> bool
Test if the document has a given node.
fn has_nodes(&self) -> bool
Test if the document has any nodes.
fn node_count(&self) -> usize
Returns the number of nodes in the document.