diff --git a/src/lib.rs b/src/lib.rs index 766f3041..272196c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg), deny(rustdoc::all))] #![cfg_attr( feature = "nightly", - feature(never_type, fn_traits, tuple_trait, unboxed_closures) + feature(new_range_api, never_type, fn_traits, tuple_trait, unboxed_closures) )] #![doc = include_str!("../README.md")] #![deny(missing_docs, clippy::undocumented_unsafe_blocks)] diff --git a/src/span.rs b/src/span.rs index 23e8d79b..466b528e 100644 --- a/src/span.rs +++ b/src/span.rs @@ -206,3 +206,41 @@ impl Span for Range { self.end.clone() } } + +#[cfg(feature = "nightly")] +impl From> for SimpleSpan { + fn from(range: std::range::Range) -> Self { + SimpleSpan { + start: range.start, + end: range.end, + context: (), + } + } +} + +#[cfg(feature = "nightly")] +impl From> for std::range::Range { + fn from(span: SimpleSpan) -> Self { + std::range::Range { + start: span.start, + end: span.end, + } + } +} + +#[cfg(feature = "nightly")] +impl Span for std::range::Range { + type Context = (); + type Offset = T; + + fn new(_context: Self::Context, range: Range) -> Self { + range.into() + } + fn context(&self) -> Self::Context {} + fn start(&self) -> Self::Offset { + self.start.clone() + } + fn end(&self) -> Self::Offset { + self.end.clone() + } +}