Unnamed repository; edit this file 'description' to name the repository.
Tuple-struct ctor is the canonical way to create a ranges
Aleksey Kladov 2020-03-09
parent 4166069 · commit 7d86273
-rw-r--r--lib/text-size/src/range.rs25
-rw-r--r--lib/text-size/tests/main.rs2
2 files changed, 14 insertions, 13 deletions
diff --git a/lib/text-size/src/range.rs b/lib/text-size/src/range.rs
index 8febcad082..7e01b12e9f 100644
--- a/lib/text-size/src/range.rs
+++ b/lib/text-size/src/range.rs
@@ -41,18 +41,19 @@ impl fmt::Debug for TextRange {
}
}
+/// Creates a new `TextRange` with given `start` and `end.
+///
+/// # Panics
+///
+/// Panics if `end < start`.
+#[allow(non_snake_case)]
+pub fn TextRange(start: TextSize, end: TextSize) -> TextRange {
+ assert!(start <= end);
+ TextRange { start, end }
+}
+
/// Identity methods.
impl TextRange {
- /// Creates a new `TextRange` with given `start` and `end.
- ///
- /// # Panics
- ///
- /// Panics if `end < start`.
- pub fn new(start: TextSize, end: TextSize) -> TextRange {
- assert!(start <= end);
- TextRange { start, end }
- }
-
/// The start point of this range.
pub const fn start(self) -> TextSize {
self.start
@@ -94,14 +95,14 @@ impl TextRange {
if end < start {
return None;
}
- Some(TextRange::new(start, end))
+ Some(TextRange(start, end))
}
/// The smallest range that completely contains both ranges.
pub fn covering(lhs: TextRange, rhs: TextRange) -> TextRange {
let start = cmp::min(lhs.start(), rhs.start());
let end = cmp::max(lhs.end(), rhs.end());
- TextRange::new(start, end)
+ TextRange(start, end)
}
/// Check if this range contains a point.
diff --git a/lib/text-size/tests/main.rs b/lib/text-size/tests/main.rs
index e25f59bacf..9a20cf9819 100644
--- a/lib/text-size/tests/main.rs
+++ b/lib/text-size/tests/main.rs
@@ -5,7 +5,7 @@ fn size(x: u32) -> TextSize {
}
fn range(x: ops::Range<u32>) -> TextRange {
- TextRange::new(x.start.into(), x.end.into())
+ TextRange(x.start.into(), x.end.into())
}
#[test]