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

Introduce CountedInput. a wrapper which counts the number of bytes successfully read #630

Merged
merged 6 commits into from
Sep 24, 2024

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Sep 22, 2024

I saw some code which tries to track the number of byte read with remaining_len. But remaining_len don't always give information.

I think it is better to provide an accurate counter.

I used u64 because it made the code simpler. And more general purpose.

Otherwise I was thinking using a type:

enum Count {
    Exact(u32),
    MaxReached,
}

and do the count in u32.

But most machine being 64bit, I think it should execute good.

@shawntabrizi
Copy link
Member

fyi we also have saturated_inc() which mutates in place and adds one.

@bkchr
Copy link
Member

bkchr commented Sep 22, 2024

fyi we also have saturated_inc() which mutates in place and adds one.

No in the standard library (which is only used in this crate)

@ggwpez ggwpez merged commit 2c61d4a into master Sep 24, 2024
17 checks passed
@gui1117 gui1117 deleted the gui-counted-input branch September 24, 2024 12:53
@gui1117 gui1117 mentioned this pull request Nov 2, 2024
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.

4 participants