Skip to content

Commit 10a8755

Browse files
Fix SimpleSpan method headers (#721)
* Remove SimpleSpan::new method * Add SimpleSpan context to From implementations * Remove SimpleSpan::splat * Require no context on SimpleSpan -> Range
1 parent 4ab25b0 commit 10a8755

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

examples/nested_spans.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ fn main() {
4949
let tokens = [
5050
(
5151
Token::Parens(vec![
52-
(Token::Num(2), SimpleSpan::new(1, 2)),
53-
(Token::Add, SimpleSpan::new(3, 4)),
54-
(Token::Num(3), SimpleSpan::new(5, 6)),
52+
(Token::Num(2), SimpleSpan::new((), 1..2)),
53+
(Token::Add, SimpleSpan::new((), 3..4)),
54+
(Token::Num(3), SimpleSpan::new((), 5..6)),
5555
]),
56-
SimpleSpan::new(0, 7),
56+
SimpleSpan::new((), 0..7),
5757
),
58-
(Token::Mul, SimpleSpan::new(8, 9)),
59-
(Token::Num(4), SimpleSpan::new(10, 11)),
58+
(Token::Mul, SimpleSpan::new((), 8..9)),
59+
(Token::Num(4), SimpleSpan::new((), 10..11)),
6060
];
6161

62-
let eoi = SimpleSpan::new(11, 11); // Example EoI
62+
let eoi = SimpleSpan::new((), 11..11); // Example EoI
6363

6464
assert_eq!(
6565
parser(make_input)

src/span.rs

+5-22
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,10 @@ pub struct SimpleSpan<T = usize, C = ()> {
9494
context: C,
9595
}
9696

97-
impl<T> SimpleSpan<T> {
98-
/// Create a new `SimpleSpan` from a start and end offset
99-
pub fn new(start: T, end: T) -> SimpleSpan<T> {
100-
SimpleSpan {
101-
start,
102-
end,
103-
context: (),
104-
}
105-
}
106-
107-
/// Create a new `SimpleSpan` from a single offset, useful for an EOI (End Of Input) span.
108-
pub fn splat(offset: T) -> SimpleSpan<T>
109-
where
110-
T: Clone,
111-
{
112-
Self::new(offset.clone(), offset)
113-
}
114-
97+
impl<T, C> SimpleSpan<T, C> {
11598
/// Convert this span into a [`std::ops::Range`].
11699
pub fn into_range(self) -> Range<T> {
117-
self.into()
100+
self.start..self.end
118101
}
119102
}
120103

@@ -128,7 +111,7 @@ impl<T> From<Range<T>> for SimpleSpan<T> {
128111
}
129112
}
130113

131-
impl<T> From<SimpleSpan<T>> for Range<T> {
114+
impl<T> From<SimpleSpan<T, ()>> for Range<T> {
132115
fn from(span: SimpleSpan<T>) -> Self {
133116
Range {
134117
start: span.start,
@@ -155,15 +138,15 @@ where
155138
}
156139
}
157140

158-
impl<T> IntoIterator for SimpleSpan<T>
141+
impl<T, C> IntoIterator for SimpleSpan<T, C>
159142
where
160143
Range<T>: Iterator<Item = T>,
161144
{
162145
type IntoIter = Range<T>;
163146
type Item = T;
164147

165148
fn into_iter(self) -> Self::IntoIter {
166-
self.into()
149+
self.start..self.end
167150
}
168151
}
169152

0 commit comments

Comments
 (0)