Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/text-size/src/range.rs')
-rw-r--r--lib/text-size/src/range.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/text-size/src/range.rs b/lib/text-size/src/range.rs
index 4a98deec56..9b981642d1 100644
--- a/lib/text-size/src/range.rs
+++ b/lib/text-size/src/range.rs
@@ -44,8 +44,8 @@ impl TextRange {
/// assert_eq!(range.len(), end - start);
/// ```
#[inline]
- pub fn new(start: TextSize, end: TextSize) -> TextRange {
- assert!(start <= end);
+ pub const fn new(start: TextSize, end: TextSize) -> TextRange {
+ assert!(start.raw <= end.raw);
TextRange { start, end }
}
@@ -65,8 +65,8 @@ impl TextRange {
/// assert_eq!(&text[range], "23456")
/// ```
#[inline]
- pub fn at(offset: TextSize, len: TextSize) -> TextRange {
- TextRange::new(offset, offset + len)
+ pub const fn at(offset: TextSize, len: TextSize) -> TextRange {
+ TextRange::new(offset, TextSize::new(offset.raw + len.raw))
}
/// Create a zero-length range at the specified offset (`offset..offset`).
@@ -82,7 +82,7 @@ impl TextRange {
/// assert_eq!(range, TextRange::new(point, point));
/// ```
#[inline]
- pub fn empty(offset: TextSize) -> TextRange {
+ pub const fn empty(offset: TextSize) -> TextRange {
TextRange {
start: offset,
end: offset,
@@ -104,9 +104,9 @@ impl TextRange {
/// assert_eq!(range, TextRange::at(0.into(), point));
/// ```
#[inline]
- pub fn up_to(end: TextSize) -> TextRange {
+ pub const fn up_to(end: TextSize) -> TextRange {
TextRange {
- start: 0.into(),
+ start: TextSize::new(0),
end,
}
}