Skip to content

Commit

Permalink
fix(partial): Clarify Needed::Size is for offset, not tokens
Browse files Browse the repository at this point in the history
Inspired by #578
  • Loading branch information
epage committed Aug 1, 2024
1 parent 43b3c53 commit c956f64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/binary/bits/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn test_incomplete_bits() {

assert!(result.is_err());
let error = result.err().unwrap();
assert_eq!("Parsing requires 2 bytes/chars", error.to_string());
assert_eq!("Parsing requires 2 more data", error.to_string());
}

#[test]
Expand Down
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ pub type PResult<O, E = ContextError> = Result<O, ErrMode<E>>;
pub enum Needed {
/// Needs more data, but we do not know how much
Unknown,
/// Contains the required data size in bytes
/// Contains a lower bound on the buffer offset needed to finish parsing
///
/// For byte/`&str` streams, this translates to bytes
Size(NonZeroUsize),
}

Expand Down Expand Up @@ -253,7 +255,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ErrMode::Incomplete(Needed::Size(u)) => write!(f, "Parsing requires {u} bytes/chars"),
ErrMode::Incomplete(Needed::Size(u)) => write!(f, "Parsing requires {u} more data"),
ErrMode::Incomplete(Needed::Unknown) => write!(f, "Parsing requires more data"),
ErrMode::Cut(c) => write!(f, "Parsing Failure: {c:?}"),
ErrMode::Backtrack(c) => write!(f, "Parsing Error: {c:?}"),
Expand Down

0 comments on commit c956f64

Please sign in to comment.