Last active
December 20, 2019 04:31
-
-
Save Lucretiel/6877c3c7888cd43c76686a905ba1c434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | |
enum Sign { | |
Positive, | |
Negative, | |
} | |
/// Partially parse a signed integer. Return the sign (if present) and | |
/// the unsigned integer part | |
fn parse_signed<E>(input: &str) -> IResult<&str, (Option<Sign>, u64), E> { | |
pair( | |
opt(alt(( | |
value(Sign::Positive, char('+')), | |
value(Sign::Negative, char('-')), | |
))), | |
map_res(digit1, u64::from_str), | |
)(input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment