From 36b86df9f51984405efa6f38be8bbb984d605207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 16 Aug 2021 23:46:32 -0700 Subject: [PATCH] feat(protocol): implement From<(usize, usize)> for SourceSpan --- README.md | 10 ++-------- src/protocol.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 35ff4ed8..bd0b5989 100644 --- a/README.md +++ b/README.md @@ -104,14 +104,8 @@ fn pretend_this_is_main() -> Result<(), MyBad> { Err(MyBad { src: Arc::new(src), filename: "bad_file.rs".into(), - snip: SourceSpan { - start: 0.into(), - end: (len - 1).into(), - }, - bad_bit: SourceSpan { - start: 9.into(), - end: 12.into(), - }, + snip: (0, (len - 1)).into(), + bad_bit: (9, 12).into(), }) } ``` diff --git a/src/protocol.rs b/src/protocol.rs index 77747f1c..d7ccf444 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -215,6 +215,15 @@ impl SourceSpan { } } +impl From<(ByteOffset, ByteOffset)> for SourceSpan { + fn from((start, end): (ByteOffset, ByteOffset)) -> Self { + Self { + start: start.into(), + end: end.into(), + } + } +} + /** "Raw" type for the byte offset from the beginning of a [Source]. */