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

DRAFT for adding Parser type #356

Closed
wants to merge 1 commit into from

Conversation

sivadeilra
Copy link

I use the zerocopy crate extensively in my work. I find myself writing this Parser type over and over in different variations in different projects. It seems like the best home for Parser is in the zerocopy 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 on Ref::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.

@google-cla
Copy link

google-cla bot commented Sep 8, 2023

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.

@sivadeilra
Copy link
Author

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.)

@@ -49,6 +49,7 @@ derive = ["zerocopy-derive"]
alloc = []
simd = []
simd-nightly = ["simd"]
std = []
Copy link
Author

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;
Copy link
Author

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.

@joshlf
Copy link
Member

joshlf commented Sep 26, 2023

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.

@joshlf joshlf closed this Sep 26, 2023
@joshlf joshlf mentioned this pull request May 20, 2024
43 tasks
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.

2 participants