Skip to content

Commit

Permalink
Implement Display for ByteOffset
Browse files Browse the repository at this point in the history
Without this patch ErrorTree<BytesOffset> does not implement Error which
makes using it (e.g. with final_parser) a lot more cumbersome.
  • Loading branch information
asdfuser committed Aug 11, 2022
1 parent f5cc556 commit 3513333
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/final_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ impl<I> RecreateContext<I> for I {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ByteOffset(pub usize);

impl Display for ByteOffset {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if f.alternate() {
write!(f, "byte offset {}", self.0)
} else {
write!(f, "{}", self.0)
}
}
}

impl<I: Offset> RecreateContext<I> for ByteOffset {
fn recreate_context(original_input: I, tail: I) -> Self {
ByteOffset(original_input.offset(&tail))
Expand Down

0 comments on commit 3513333

Please sign in to comment.