Skip to content

Commit 06d0c2b

Browse files
authored
Add Bibliography::keys (#61)
1 parent f1067e2 commit 06d0c2b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ impl Bibliography {
233233
self.entries.iter_mut()
234234
}
235235

236+
/// An iterator over the bibliography's entry keys.
237+
pub fn keys(&self) -> impl Iterator<Item = &str> {
238+
self.entries.iter().map(|entry| &*entry.key)
239+
}
240+
236241
/// Consume this struct and return a vector of the bibliography's entries.
237242
pub fn into_vec(self) -> Vec<Entry> {
238243
self.entries
@@ -1001,6 +1006,18 @@ mod tests {
10011006
};
10021007
}
10031008

1009+
#[test]
1010+
fn test_keys() {
1011+
let contents = fs::read_to_string("tests/editortypes.bib").unwrap();
1012+
1013+
let bibliography = Bibliography::parse(&contents).unwrap();
1014+
1015+
assert_eq!(
1016+
bibliography.keys().collect::<Vec<_>>(),
1017+
&["acerolaThisDifferenceGaussians2022", "mozart_KV183_1773", "Smith2018"]
1018+
);
1019+
}
1020+
10041021
#[test]
10051022
fn test_gral_paper() {
10061023
dump_debug("tests/gral.bib");

0 commit comments

Comments
 (0)