Skip to content

Commit da93594

Browse files
committed
Tuple-struct ctor is the canonical way to create a ranges
1 parent cd1f821 commit da93594

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/range.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,19 @@ impl fmt::Debug for TextRange {
4141
}
4242
}
4343

44+
/// Creates a new `TextRange` with given `start` and `end.
45+
///
46+
/// # Panics
47+
///
48+
/// Panics if `end < start`.
49+
#[allow(non_snake_case)]
50+
pub fn TextRange(start: TextSize, end: TextSize) -> TextRange {
51+
assert!(start <= end);
52+
TextRange { start, end }
53+
}
54+
4455
/// Identity methods.
4556
impl TextRange {
46-
/// Creates a new `TextRange` with given `start` and `end.
47-
///
48-
/// # Panics
49-
///
50-
/// Panics if `end < start`.
51-
pub fn new(start: TextSize, end: TextSize) -> TextRange {
52-
assert!(start <= end);
53-
TextRange { start, end }
54-
}
55-
5657
/// The start point of this range.
5758
pub const fn start(self) -> TextSize {
5859
self.start
@@ -94,14 +95,14 @@ impl TextRange {
9495
if end < start {
9596
return None;
9697
}
97-
Some(TextRange::new(start, end))
98+
Some(TextRange(start, end))
9899
}
99100

100101
/// The smallest range that completely contains both ranges.
101102
pub fn covering(lhs: TextRange, rhs: TextRange) -> TextRange {
102103
let start = cmp::min(lhs.start(), rhs.start());
103104
let end = cmp::max(lhs.end(), rhs.end());
104-
TextRange::new(start, end)
105+
TextRange(start, end)
105106
}
106107

107108
/// Check if this range contains a point.

tests/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn size(x: u32) -> TextSize {
55
}
66

77
fn range(x: ops::Range<u32>) -> TextRange {
8-
TextRange::new(x.start.into(), x.end.into())
8+
TextRange(x.start.into(), x.end.into())
99
}
1010

1111
#[test]

0 commit comments

Comments
 (0)