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

Try get methods for buf #753

Merged
merged 15 commits into from
Jan 21, 2025
Merged

Conversation

hpenne
Copy link
Contributor

@hpenne hpenne commented Jan 8, 2025

Adds fallible try_get_ methods to Buf. The methods align with the existing get_ methods. All of them, so this is a lot of lines but most of it is documentation. Note that I copied and adapted buf_get_impl to make try_buf_get_impl. It is possible to avoid some code duplication by calling buf_get_impl instead, but that will checked the remaining bytes twice, and buf_get_impl is performance optimized so I chose not to do that.

This code borrows some from the existing PR for this feature by @caelunshun, but that is old with lots of conflicts, so I chose to reimplement it from the current master instead.

I would rater have used from_be_bytes etc. for the floats as that seems more portable for NaN values, but it seems that the supported rust version is perhaps one minor version too old for that.

Closes #254

src/buf/buf_impl.rs Outdated Show resolved Hide resolved
src/buf/buf_impl.rs Outdated Show resolved Hide resolved
hpenne added 2 commits January 9, 2025 18:22
…_get_impl macro is implemented through buf_try_get_impl to avoid code duplication, and copy_to_slice is implemented through try_copy_to_slice.
src/buf/buf_impl.rs Show resolved Hide resolved
src/buf/buf_impl.rs Outdated Show resolved Hide resolved
@hpenne
Copy link
Contributor Author

hpenne commented Jan 12, 2025

@Darksonn @paolobarbolini I think I have made the necessary changes to the comments I have received so far. I have pushed the "Resove" button on each to indicate this (I hope this was the correct thing to do in this repo, it seems to vary). I hope you have the time next week to review my changes. Also, the CI needs to be started on the latest changes.

@Darksonn
Copy link
Contributor

Thanks, clicking resolve is fine. 👍

src/buf/buf_impl.rs Outdated Show resolved Hide resolved
src/buf/buf_impl.rs Outdated Show resolved Hide resolved
src/buf/buf_impl.rs Outdated Show resolved Hide resolved
…d::io::Error using From. Used TryGetError as the parameter for panic_advance, and moved TryGetError to before panic_advance in lib.rs. Removed unwrap_advance, as calling panic_advance is now convenient enough.
@hpenne
Copy link
Contributor Author

hpenne commented Jan 20, 2025

@Darksonn I think all PR comments have been addressed now, although I was in doubt as to where it is best to define TryGetError (lib.rs or in buf_impl.rs). See also the answer to one of your comments above.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@Darksonn Darksonn merged commit 3ab876f into tokio-rs:master Jan 21, 2025
16 checks passed
@hpenne
Copy link
Contributor Author

hpenne commented Jan 21, 2025

@Darksonn I'm glad to be allowed to help out a little. The old PR from 2019 for this feature request is now obsolete and should perhaps be closed/rejected: #277

@hpenne hpenne deleted the try_get-methods-for-Buf branch January 21, 2025 14:12
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.

Request: Provide try_get_* methods
3 participants