-
Notifications
You must be signed in to change notification settings - Fork 59
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
Byte decode error #89
Conversation
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.
Thank you, I tried but haven't finished yet. So, you take the lead and I will accept your PR!
I am wondering if introducing a custom public Result type named CodecResult
, could be better.
pub type CodecResult<T> = Result<T, Box<dyn Error>>;
} | ||
|
||
None | ||
Err("The provided bytes do not satisfy the alignment requirements.")? |
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.
When I switch from zerocopy to bytemuck I will change this error string into a nicer error, more precise!
@@ -71,8 +71,8 @@ pub struct DecodeIgnore; | |||
impl heed_traits::BytesDecode<'_> for DecodeIgnore { | |||
type DItem = (); | |||
|
|||
fn bytes_decode(_bytes: &[u8]) -> Option<Self::DItem> { | |||
Some(()) | |||
fn bytes_decode(_bytes: &[u8]) -> Result<Self::DItem, Box<dyn std::error::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.
fn bytes_decode(_bytes: &[u8]) -> Result<Self::DItem, Box<dyn std::error::Error>> { | |
fn bytes_decode(_bytes: &[u8]) -> Result<Self::DItem, Box<dyn Error>> { |
By importing the Error trait into the scope.
@@ -278,7 +278,7 @@ impl PolyDatabase { | |||
{ | |||
assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); | |||
|
|||
let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; | |||
let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(|e| Error::Encoding(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.
let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(|e| Error::Encoding(e))?; | |
let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; |
Encoding(Box<dyn std::error::Error>), | ||
Decoding(Box<dyn std::error::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.
Encoding(Box<dyn std::error::Error>), | |
Decoding(Box<dyn std::error::Error>), | |
Encoding(Box<dyn Error>), | |
Decoding(Box<dyn Error>), |
Why not exposing an anyhow Result instead? |
I don't want to bring one more dependency in this crate, don't want to force users to use anyhow, using anyhow here would not bring interesting features here, and anyhow has been design to be used by binary crates. Exposing a type alias will work just fine :) |
close #88