Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ impl Context {
self.data.remove(index)
}

/// Returns an iterator over the keys of the `Context`, in sorted order.
pub fn keys(&self) -> impl Iterator<Item = &str> {
self.data.keys().map(|k| k.as_ref())
}

/// Checks if a value exists at a specific index.
pub fn contains_key(&self, index: &str) -> bool {
self.data.contains_key(index)
Expand Down Expand Up @@ -509,4 +514,14 @@ mod tests {
let mut context = Context::new();
assert_eq!(context.remove("unknown"), None);
}

#[test]
fn can_iterate_over_keys() {
let mut context = Context::new();
context.insert("b", "b");
context.insert("a", "a");

let keys: Vec<_> = context.keys().collect();
assert_eq!(keys, ["a", "b"]);
}
}