File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,11 @@ impl Bibliography {
233
233
self . entries . iter_mut ( )
234
234
}
235
235
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
+
236
241
/// Consume this struct and return a vector of the bibliography's entries.
237
242
pub fn into_vec ( self ) -> Vec < Entry > {
238
243
self . entries
@@ -1001,6 +1006,18 @@ mod tests {
1001
1006
} ;
1002
1007
}
1003
1008
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
+
1004
1021
#[ test]
1005
1022
fn test_gral_paper ( ) {
1006
1023
dump_debug ( "tests/gral.bib" ) ;
You can’t perform that action at this time.
0 commit comments