From 95200366a1639b0b729db460ae1e50cce6fee9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 17 Aug 2021 18:30:38 -0700 Subject: [PATCH] feat(offsets): more utility From impls for SourceSpan --- src/protocol.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/protocol.rs b/src/protocol.rs index 23a7af8..be4880b 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -252,6 +252,26 @@ impl> From<(T, ByteOffset, ByteOffset)> for SourceSpan { } } +impl From<(SourceOffset, SourceOffset)> for SourceSpan { + fn from((start, len): (SourceOffset, SourceOffset)) -> Self { + Self { + label: None, + offset: start, + length: len, + } + } +} + +impl> From<(T, SourceOffset, SourceOffset)> for SourceSpan { + fn from((label, start, len): (T, SourceOffset, SourceOffset)) -> Self { + Self { + label: Some(label.as_ref().into()), + offset: start, + length: len, + } + } +} + /** "Raw" type for the byte offset from the beginning of a [Source]. */