Skip to content
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

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

nytzuga
Copy link
Contributor

@nytzuga nytzuga commented Jul 28, 2023

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.

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.
@nytzuga nytzuga requested a review from xinifinity as a code owner July 28, 2023 04:16
@nytzuga nytzuga self-assigned this Jul 28, 2023
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");
Copy link
Contributor Author

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> (

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

[1] https://docs.rs/bytes/latest/bytes/#bytes

Copy link
Contributor

@xinifinity xinifinity left a 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!

@nytzuga nytzuga changed the title Draft: This is an attempt to remove api::Error:::KeyNotFound This is an attempt to remove api::Error:::KeyNotFound Jul 28, 2023
Copy link
Collaborator

@rkuris rkuris left a 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!

@rkuris rkuris changed the title This is an attempt to remove api::Error:::KeyNotFound Return Option<T> instead of erroring with api::Error:::KeyNotFound Jul 28, 2023
@rkuris rkuris merged commit 6a63290 into main Jul 28, 2023
5 checks passed
@rkuris rkuris deleted the remove-KeyNotFound-use-Option-instead branch July 28, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants