diff --git a/gemtext/src/lib.rs b/gemtext/src/lib.rs index 71ab545..f9cc830 100644 --- a/gemtext/src/lib.rs +++ b/gemtext/src/lib.rs @@ -61,7 +61,7 @@ impl ToString for Builder { fn to_string(&self) -> String { let len: usize = self.nodes.iter().map(Node::estimate_len).sum(); // sum up node lengths let mut bytes = Vec::with_capacity(len + self.nodes.len()); // add in inter-node newlines - render(&self.nodes, &mut bytes).unwrap(); // Writing to a string shouldn't produce errors + render(self, &mut bytes).unwrap(); // Writing to a string shouldn't produce errors unsafe { // This is safe because bytes is composed of Strings. We could have this as @@ -73,6 +73,20 @@ impl ToString for Builder { } } +impl AsRef<[Node]> for Builder { + /// Get a reference to the internal node list of this builder + fn as_ref(&self) -> &[Node] { + self.nodes.as_ref() + } +} + +impl AsMut<[Node]> for Builder { + /// Get a mutable reference to the internal node list of this builder + fn as_mut(&mut self) -> &mut [Node] { + self.nodes.as_mut() + } +} + /// Render a set of nodes as a document to a writer. pub fn render(nodes: impl AsRef<[Node]>, out: &mut impl Write) -> io::Result<()> { use Node::*;