From 101a020a2a37dfc7e67fc0a8abea06974ce6aece Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Thu, 21 Nov 2024 16:43:27 -0500 Subject: [PATCH] feat: ergonomics for the SpanRange enum construction --- src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7f95a6b..bf07dda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,6 +50,30 @@ pub enum SpanRange { RangeFull(std::ops::RangeFull), } +impl From> for SpanRange { + fn from(value: std::ops::Range) -> Self { + SpanRange::Range(value) + } +} + +impl From> for SpanRange { + fn from(value: std::ops::RangeTo) -> Self { + SpanRange::RangeTo(value) + } +} + +impl From> for SpanRange { + fn from(value: std::ops::RangeFrom) -> Self { + SpanRange::RangeFrom(value) + } +} + +impl From for SpanRange { + fn from(value: std::ops::RangeFull) -> Self { + SpanRange::RangeFull(value) + } +} + /// An input that can provide a span of a range of the input. pub trait Span { fn span(&self, idx: SpanRange) -> O;