-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return Option<T> instead of erroring with api::Error:::KeyNotFound #171
Conversation
Instead of returning an Error when a key is not found, an Option will be returned. This PR also modifies all the other functions inside the `api::DbView`, maybe only `val` should be updated at this stage.
assert_eq!(proposal3.val(b"k").await.unwrap(), b"v"); | ||
assert_eq!(proposal3.val(b"z").await.unwrap(), b"undo"); | ||
assert_eq!(proposal3.val(b"k").await.unwrap().unwrap(), b"v"); | ||
assert_eq!(proposal3.val(b"z").await.unwrap().unwrap(), b"undo"); |
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 just follow the pattern, but if it was up to me I would just change it to assert_eq!(proposal3.val(b"z").await, Ok(Some(b"undo")));
.
Also, it think it would be nice to use bytes::Bytes instead of raw Vec<u8>
(
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.
We eventually will be returning a reference instead of an owned value, but we want to get something out soon so we're sticking with owned for now and will change that later.
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.
The beauty of bytes::Bytes
is that you can return the ownership but the memory segment is referenced counted internally[1].
People are free to copy into a bytes::BytesMut
to modify, but bytes::Bytes
are read only.
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.
Thanks for the contribution!
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.
LGTM! Thanks for doing this!
Instead of returning an Error when a key is not found, an Option will be returned.
This PR also modifies all the other functions inside the
api::DbView
, maybe onlyval
should be updated at this stage.