aboutsummaryrefslogtreecommitdiff
path: root/src/grid/row.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/grid/row.rs')
-rw-r--r--src/grid/row.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/grid/row.rs b/src/grid/row.rs
index 69a4f2b2..7c12bf99 100644
--- a/src/grid/row.rs
+++ b/src/grid/row.rs
@@ -15,7 +15,7 @@
//! Defines the Row type which makes up lines in the grid
use std::ops::{Index, IndexMut};
-use std::ops::{Range, RangeTo, RangeFrom, RangeFull};
+use std::ops::{Range, RangeTo, RangeFrom, RangeFull, RangeToInclusive};
use std::cmp::{max, min};
use std::slice;
@@ -200,3 +200,20 @@ impl<T> IndexMut<RangeFull> for Row<T> {
&mut self.inner[..]
}
}
+
+impl<T> Index<RangeToInclusive<Column>> for Row<T> {
+ type Output = [T];
+
+ #[inline]
+ fn index(&self, index: RangeToInclusive<Column>) -> &[T] {
+ &self.inner[..=(index.end.0)]
+ }
+}
+
+impl<T> IndexMut<RangeToInclusive<Column>> for Row<T> {
+ #[inline]
+ fn index_mut(&mut self, index: RangeToInclusive<Column>) -> &mut [T] {
+ self.occ = max(self.occ, *index.end);
+ &mut self.inner[..=(index.end.0)]
+ }
+}