Skip to content

Commit

Permalink
ExactSizeIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Sep 4, 2024
1 parent 143ab9b commit 95df06d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/libs/registry/src/key_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ impl<'a> Iterator for KeyIterator<'a> {
})
}
}

impl<'a> ExactSizeIterator for KeyIterator<'a> {
fn len(&self) -> usize {
self.range.len()
}
}
6 changes: 6 additions & 0 deletions crates/libs/registry/src/value_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ impl<'a> Iterator for ValueIterator<'a> {
})
}
}

impl<'a> ExactSizeIterator for ValueIterator<'a> {
fn len(&self) -> usize {
self.range.len()
}
}
4 changes: 4 additions & 0 deletions crates/tests/registry/tests/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ fn keys() -> Result<()> {
let names: Vec<String> = key.keys()?.collect();
assert_eq!(names, ["one", "three", "two"]);

// The "keys" iterator implements `ExactSizeIterator`.
let iter = key.keys()?;
assert_eq!(iter.len(), 3);

let err = key.open("missing").unwrap_err();
assert_eq!(err.code(), HRESULT(0x80070002u32 as i32)); // HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
assert_eq!(err.message(), "The system cannot find the file specified.");
Expand Down
4 changes: 4 additions & 0 deletions crates/tests/registry/tests/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ fn values() -> Result<()> {
]
);

// The "values" iterator implements `ExactSizeIterator`.
let iter = key.values()?;
assert_eq!(iter.len(), 3);

Ok(())
}

0 comments on commit 95df06d

Please sign in to comment.