-
Notifications
You must be signed in to change notification settings - Fork 38
return error result from fallible iteration methods #13
Conversation
match self.get(Some(key.as_ref()), None, ffi::MDB_SET_RANGE) { | ||
Ok(_) | Err(Error::NotFound) => (), | ||
Err(error) => panic!("mdb_cursor_get returned an unexpected error: {}", error), | ||
Err(error) => return Err(error), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just e => e
? Or is there a hidden conversion happening between Result
errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just e => e
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, I'm fine with this approach, since it's both clear and minimizes dependencies. However, I'd like to make sure you're aware of https://github.com/sfackler/rust-fallible-iterator, which brings a little more machinery to the party.
|
||
assert_eq!(0, cursor.iter_dup_of(b"foo").count()); | ||
assert_eq!(0, cursor.iter_dup_of(b"foo").unwrap().count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For next time: generally I like .expect("...")
in tests, since it can help narrow down what really broke. This is especially useful when you have two .unwrap()
invocations on a single line (which you do).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger that. In this case, The changes are maintaining consistency with the existing code, which uses unwrap()
everywhere.
src/cursor.rs
Outdated
@@ -571,10 +584,30 @@ mod test { | |||
let mut i = 0; | |||
let mut count = 0u32; | |||
|
|||
for (key, data) in cursor.iter().map(|x| x.unwrap()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh; these little lambda functions are pretty idiomatic.
src/cursor.rs
Outdated
@@ -602,10 +602,6 @@ mod test { | |||
let mut i = 0; | |||
let mut count = 0u32; | |||
for result in cursor.iter() { | |||
// let (key, data) = match result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did wonder.
Thanks, that's good to know. If I understand correctly, |
Since #14 subsumes this PR (includes these changes), and you seemed optimistic about that one (after some changes) when we discussed it, I'll close this PR in favor of that one. |
This branch implements the suggestion in danburkert#42 by returning an error result from fallible iteration methods (
Cursor.iter*()
andIterator.next()
) when those methods fail. See that issue for more info about the changes.(I've previously requested integration of these changes upstream in danburkert#44 and would like to move forward with these changes downstream while awaiting that integration.)