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

Fix broken example README.md #25

Merged
merged 1 commit into from
Nov 23, 2023
Merged

Fix broken example README.md #25

merged 1 commit into from
Nov 23, 2023

Conversation

avan-pra
Copy link
Contributor

The example to know how much of the input has been consumed wasn't compiling.

use atoi::FromRadix10;

/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest<I: FromRadix10>(text: &[u8]) -> Option<(&[u8], I)> {
    match I::from_radix_10(text) {
        (_, 0) => None,
        (n, used) => Some((&[used..], n)),
    }
}

fn main() {
    println!("{:?}", atoi_with_rest::<u32>(b"25aaa"));
}

image

Fixed it by adding the text variable at the right place (see commit).

(using the above main)

$ cargo run
[...]
Some(([97, 97, 97], 25))

Did not compile because `text` variable wasn't there
@pacman82
Copy link
Owner

@avan-pra Thank you!

@pacman82 pacman82 merged commit 7a637ba into pacman82:main Nov 23, 2023
1 check passed
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