feat: even more ergonomic
This commit is contained in:
parent
101a020a2a
commit
562a78eb3f
10
src/lib.rs
10
src/lib.rs
@ -76,7 +76,7 @@ impl From<std::ops::RangeFull> for SpanRange {
|
|||||||
|
|
||||||
/// An input that can provide a span of a range of the input.
|
/// An input that can provide a span of a range of the input.
|
||||||
pub trait Span<O> {
|
pub trait Span<O> {
|
||||||
fn span(&self, idx: SpanRange) -> O;
|
fn span<R: Into<SpanRange>>(&self, idx: R) -> O;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The interface for types that can peek ahead to the next item.
|
/// The interface for types that can peek ahead to the next item.
|
||||||
@ -169,8 +169,8 @@ impl<'a, T: Debug + 'a> Cursor for SliceCursor<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Debug + 'a> Span<&'a [T]> for SliceCursor<'a, T> {
|
impl<'a, T: Debug + 'a> Span<&'a [T]> for SliceCursor<'a, T> {
|
||||||
fn span(&self, idx: SpanRange) -> &'a [T] {
|
fn span<R: Into<SpanRange>>(&self, idx: R) -> &'a [T] {
|
||||||
match idx {
|
match idx.into() {
|
||||||
SpanRange::Range(r) => self.source.index(r),
|
SpanRange::Range(r) => self.source.index(r),
|
||||||
SpanRange::RangeTo(r) => self.source.index(r),
|
SpanRange::RangeTo(r) => self.source.index(r),
|
||||||
SpanRange::RangeFrom(r) => self.source.index(r),
|
SpanRange::RangeFrom(r) => self.source.index(r),
|
||||||
@ -293,8 +293,8 @@ impl<'a> From<&'a str> for StrCursor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Span<&'a str> for StrCursor<'a> {
|
impl<'a> Span<&'a str> for StrCursor<'a> {
|
||||||
fn span(&self, idx: SpanRange) -> &'a str {
|
fn span<R: Into<SpanRange>>(&self, idx: R) -> &'a str {
|
||||||
match idx {
|
match idx.into() {
|
||||||
SpanRange::Range(r) => self.source.index(r),
|
SpanRange::Range(r) => self.source.index(r),
|
||||||
SpanRange::RangeTo(r) => self.source.index(r),
|
SpanRange::RangeTo(r) => self.source.index(r),
|
||||||
SpanRange::RangeFrom(r) => self.source.index(r),
|
SpanRange::RangeFrom(r) => self.source.index(r),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user