Skip to content

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

Merged
ggwpez merged 6 commits intomasterfrom
gui-counted-input
Sep 24, 2024
Merged

Introduce CountedInput. a wrapper which counts the number of bytes successfully read#630
ggwpez merged 6 commits intomasterfrom
gui-counted-input

Conversation

@gui1117
Copy link
Copy Markdown
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
Copy Markdown
Member

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

@bkchr
Copy link
Copy Markdown
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
@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