-
Notifications
You must be signed in to change notification settings - Fork 109
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
DRAFT for adding Parser type #356
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Hmmm, it's showing my CLA as being invalid. I had a CLA on file in 2021. I'll check on getting that refreshed. (I've made contributions to this repo before.) |
3c93f88
to
e3e22bc
Compare
@@ -49,6 +49,7 @@ derive = ["zerocopy-derive"] | |||
alloc = [] | |||
simd = [] | |||
simd-nightly = ["simd"] | |||
std = [] |
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 here because I added a ParserError
type. When std
is available, ParserError
implements the std::error::Error
trait.
|
||
/// This type is returned by Parser methods. | ||
#[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
pub struct ParserError; |
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 ParserError
type exists so that users of the crate can define their own From<ParserError>
implementations, which convert from ParserError
to their own error types. Because ParserError
implements std::error::Error
, it can also be converted to anyhow::Error
.
Both of these are ergonomic benefits, and they would be lost if these functions returned Option
instead.
Discussed offline; I'm going to close this for the time being, but for those following along at home: We have active work ongoing to add support for a higher-level buffer/parsing framework built around zerocopy. If you're interested in participating in development or have suggestions or requested use cases, please reach out. |
I use the
zerocopy
crate extensively in my work. I find myself writing thisParser
type over and over in different variations in different projects. It seems like the best home forParser
is in thezerocopy
crate itself.This is a DRAFT PR. If you agree with the general idea of this PR, I'll write better doc comments, make the API more consistent, etc. I think the core idea is sound:
Parser
is a type that decodes values and references from a&[u8]
, in a form that is much more convenient than repeated calls to methods onRef::new_slice_from...
.It looks like my editor has chopped off some whitespace at the end of lines. I'll revert that before submitting real PR.