From 3513333e72e4a61114dc3c5516ba7fed928885d0 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Sun, 27 Jun 2021 22:37:12 +0200 Subject: [PATCH] Implement Display for ByteOffset Without this patch ErrorTree does not implement Error which makes using it (e.g. with final_parser) a lot more cumbersome. --- src/final_parser.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/final_parser.rs b/src/final_parser.rs index e8781f4..51d9f21 100644 --- a/src/final_parser.rs +++ b/src/final_parser.rs @@ -72,6 +72,16 @@ impl RecreateContext 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 RecreateContext for ByteOffset { fn recreate_context(original_input: I, tail: I) -> Self { ByteOffset(original_input.offset(&tail))