From 06d0c2b10a749fd3b2c799b32077382b796a5609 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:07:24 -0300 Subject: [PATCH] Add `Bibliography::keys` (#61) --- src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3fa06bb..fbb1a6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,6 +233,11 @@ impl Bibliography { self.entries.iter_mut() } + /// An iterator over the bibliography's entry keys. + pub fn keys(&self) -> impl Iterator { + self.entries.iter().map(|entry| &*entry.key) + } + /// Consume this struct and return a vector of the bibliography's entries. pub fn into_vec(self) -> Vec { self.entries @@ -1001,6 +1006,18 @@ mod tests { }; } + #[test] + fn test_keys() { + let contents = fs::read_to_string("tests/editortypes.bib").unwrap(); + + let bibliography = Bibliography::parse(&contents).unwrap(); + + assert_eq!( + bibliography.keys().collect::>(), + &["acerolaThisDifferenceGaussians2022", "mozart_KV183_1773", "Smith2018"] + ); + } + #[test] fn test_gral_paper() { dump_debug("tests/gral.bib");