Skip to content

Commit

Permalink
Merge pull request #694 from epage/cl
Browse files Browse the repository at this point in the history
refactor: Minor clean up
  • Loading branch information
epage authored Jan 14, 2025
2 parents 795e30c + 55bd745 commit 5ffcd7c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/binary/bits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ where
Err(ErrMode::Incomplete(Needed::Unknown)) => Err(ErrMode::Incomplete(Needed::Unknown)),
Err(ErrMode::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(BYTE) {
Some(v) => ErrMode::Incomplete(Needed::new(v)),
None => ErrMode::Cut(BitError::assert(
None => ErrMode::assert(
bit_input,
"overflow in turning needed bytes into needed bits",
)),
),
}),
Err(e) => Err(ErrorConvert::convert(e)),
}
Expand Down
18 changes: 6 additions & 12 deletions src/combinator/core.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::combinator::trace;
use crate::error::{ErrMode, ErrorKind, Needed, ParserError};
use crate::error::{ErrMode, ErrorKind, ParserError};
use crate::stream::Stream;
use crate::*;

Expand Down Expand Up @@ -397,7 +397,7 @@ where
{
parser: F,
input: I,
state: Option<State<E>>,
state: Option<State<ErrMode<E>>>,
o: core::marker::PhantomData<O>,
}

Expand All @@ -410,8 +410,7 @@ where
pub fn finish(mut self) -> PResult<(I, ()), E> {
match self.state.take().unwrap() {
State::Running | State::Done => Ok((self.input, ())),
State::Failure(e) => Err(ErrMode::Cut(e)),
State::Incomplete(i) => Err(ErrMode::Incomplete(i)),
State::Cut(e) => Err(e),
}
}
}
Expand All @@ -437,12 +436,8 @@ where
self.state = Some(State::Done);
None
}
Err(ErrMode::Cut(e)) => {
self.state = Some(State::Failure(e));
None
}
Err(ErrMode::Incomplete(i)) => {
self.state = Some(State::Incomplete(i));
Err(e) => {
self.state = Some(State::Cut(e));
None
}
}
Expand All @@ -455,8 +450,7 @@ where
enum State<E> {
Running,
Done,
Failure(E),
Incomplete(Needed),
Cut(E),
}

/// Succeed, consuming no input
Expand Down
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl<I: Stream, E: ParserError<I>> ParserError<I> for ErrMode<E> {
ErrMode::Backtrack(E::from_error_kind(input, kind))
}

#[cfg_attr(debug_assertions, track_caller)]
#[inline(always)]
fn assert(input: &I, message: &'static str) -> Self
where
Expand Down Expand Up @@ -286,7 +285,6 @@ pub trait ParserError<I: Stream>: Sized {
fn from_error_kind(input: &I, kind: ErrorKind) -> Self;

/// Process a parser assertion
#[cfg_attr(debug_assertions, track_caller)]
#[inline(always)]
fn assert(input: &I, _message: &'static str) -> Self
where
Expand Down

0 comments on commit 5ffcd7c

Please sign in to comment.