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]

Construct a new, empty document

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.

Inserts a node into the document.

If there is already a node with the given name, replace it and return the old node.

Remove a node from the document.

Returns the deleted node, if it exists.

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.

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.

Get an iterable of (&name, &node) pairs

Test if the document is empty - if it has no nodes.

Test if the document has a given node.

Test if the document has any nodes.

Returns the number of nodes in the document.

Trait Implementations

impl Debug for Document
[src]

Formats the value using the given formatter.

impl PartialEq for Document
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.