Skip to content

Instantly share code, notes, and snippets.

@Lucretiel
Last active December 20, 2019 04:31
Show Gist options
  • Save Lucretiel/6877c3c7888cd43c76686a905ba1c434 to your computer and use it in GitHub Desktop.
Save Lucretiel/6877c3c7888cd43c76686a905ba1c434 to your computer and use it in GitHub Desktop.
#[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