aboutsummaryrefslogtreecommitdiff
path: root/src/bits/complete.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bits/complete.rs')
-rw-r--r--src/bits/complete.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/bits/complete.rs b/src/bits/complete.rs
index f868ec2..bce4df4 100644
--- a/src/bits/complete.rs
+++ b/src/bits/complete.rs
@@ -1,13 +1,15 @@
-//! bit level parsers
+//! Bit level parsers
//!
use crate::error::{ErrorKind, ParseError};
use crate::internal::{Err, IResult};
-use crate::lib::std::ops::{AddAssign, RangeFrom, Shl, Shr, Div};
+use crate::lib::std::ops::{AddAssign, Div, RangeFrom, Shl, Shr};
use crate::traits::{InputIter, InputLength, Slice, ToUsize};
-/// generates a parser taking `count` bits
-pub fn take<I, O, C, E: ParseError<(I, usize)>>(count: C) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
+/// Generates a parser taking `count` bits
+pub fn take<I, O, C, E: ParseError<(I, usize)>>(
+ count: C,
+) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
C: ToUsize,
@@ -20,11 +22,14 @@ where
} else {
let cnt = (count + bit_offset).div(8);
if input.input_len() * 8 < count + bit_offset {
- Err(Err::Error(E::from_error_kind((input, bit_offset), ErrorKind::Eof)))
+ Err(Err::Error(E::from_error_kind(
+ (input, bit_offset),
+ ErrorKind::Eof,
+ )))
} else {
- let mut acc:O = (0 as u8).into();
- let mut offset: usize = bit_offset;
- let mut remaining: usize = count;
+ let mut acc: O = (0 as u8).into();
+ let mut offset: usize = bit_offset;
+ let mut remaining: usize = count;
let mut end_offset: usize = 0;
for byte in input.iter_elements().take(cnt + 1) {
@@ -47,14 +52,17 @@ where
offset = 0;
}
}
- Ok(( (input.slice(cnt..), end_offset) , acc))
+ Ok(((input.slice(cnt..), end_offset), acc))
}
}
}
}
-/// generates a parser taking `count` bits and comparing them to `pattern`
-pub fn tag<I, O, C, E: ParseError<(I, usize)>>(pattern: O, count: C) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
+/// Generates a parser taking `count` bits and comparing them to `pattern`
+pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
+ pattern: O,
+ count: C,
+) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
C: ToUsize,