Add iterators and convenience functions

sloane
Jul 15, 2022, 2:37 AM
YCMZOCRWB24BU3ZKXSU2OHCSYYP2DYC2FVFEOAKKQWYQYIO3VJNQC

Dependencies

  • [2] 3UXSFGJY Update `gemini`: Convenience methods, make streaming parsers public; update tests
  • [*] J4PKMKJX Add root doc comment, gemtext module
  • [*] M5HGUS2T Add parser tests and fix some bugs

Change contents

  • edit in gemini/src/gemtext.rs at line 116
    [4.3379]
    [4.3379]
    }
    /// Add a link line without a name to the document.
    pub fn link_unnamed(self, to: impl Into<String>) -> Self {
    let to = to.into();
    self.push(Doc::Link { to, name: None })
  • edit in gemini/src/gemtext.rs at line 170
    [4.4914]
    [4.4914]
    }
    /// An iterator over references to the documents in the builder.
    pub fn iter(&self) -> impl Iterator<Item = &Doc> {
    self.docs.iter()
    }
    /// An iterator over mutable references to the documents in the builder.
    pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Doc> {
    self.docs.iter_mut()
  • edit in gemini/src/gemtext.rs at line 217
    [4.6661]
    [2.2713]
    impl IntoIterator for Builder {
    type Item = Doc;
    type IntoIter = std::vec::IntoIter<Doc>;
  • edit in gemini/src/gemtext.rs at line 223
    [2.2714]
    [2.2714]
    fn into_iter(self) -> Self::IntoIter {
    self.docs.into_iter()
    }
    }
  • edit in gemini/src/gemtext.rs at line 556
    [5.5534]
    [5.5534]
    #[test]
    fn test_iter() {
    let expected = [
    Doc::Blank,
    Doc::Heading(Level::One, "Wow!".to_string()),
    Doc::Quote("Wee!".to_string()),
    Doc::Link {
    to: "gemini://foo.bar".to_string(),
    name: None,
    },
    ];
    let doc = Builder::new()
    .line()
    .h1("Wow!")
    .quote("Wee!")
    .link_unnamed("gemini://foo.bar");
    for (i, actual) in doc.iter().enumerate() {
    assert_eq!(actual, &expected[i])
    }
    }