Skip to content

Instantly share code, notes, and snippets.

@kali
Created July 15, 2019 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kali/c13b31f735c15f1b36eca1e8093aab8c to your computer and use it in GitHub Desktop.
Save kali/c13b31f735c15f1b36eca1e8093aab8c to your computer and use it in GitHub Desktop.
pub fn integer<'a>(bin: bool) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], i32> {
map(pair(
cond(bin, be_i32),
cond(!bin,
map_res(
map_res(
recognize(pair(opt(tag("-")), take_while(nom::character::is_digit))),
std::str::from_utf8,
),
|s| s.parse::<i32>(),
)
)), |(a,b)| a.or(b).unwrap())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment