summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-07-02 08:25:21 -0700
committerJoe Wilm <joe@jwilm.com>2016-07-02 08:25:21 -0700
commitf2e6d66a5e8ada1bd0c860eaa3d50e100a72f68b (patch)
tree276a91a1591026dc4b39b106c2742f91f9a9764f /src
parenta2ca10643f744244c635fb9b41a3c742e35213ea (diff)
downloadalacritty-f2e6d66a5e8ada1bd0c860eaa3d50e100a72f68b.tar.gz
alacritty-f2e6d66a5e8ada1bd0c860eaa3d50e100a72f68b.zip
Improve ergonomics of iterating on grid::Row
Iterating on grid::Row types no longer requires calls to iter() or iter_mut().
Diffstat (limited to 'src')
-rw-r--r--src/grid.rs23
-rw-r--r--src/term.rs6
2 files changed, 24 insertions, 5 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 3ce15280..042aabb7 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -16,7 +16,8 @@
use std::ops::{Index, IndexMut, Deref, DerefMut, Range, RangeTo, RangeFrom, RangeFull};
use std::cmp::Ordering;
-use std::slice::{Iter, IterMut};
+use std::slice::{self, Iter, IterMut};
+use std::iter::IntoIterator;
use util::Rotate;
@@ -233,6 +234,24 @@ impl Row {
}
}
+impl<'a> IntoIterator for &'a Row {
+ type Item = &'a Cell;
+ type IntoIter = slice::Iter<'a, Cell>;
+
+ fn into_iter(self) -> slice::Iter<'a, Cell> {
+ self.iter()
+ }
+}
+
+impl<'a> IntoIterator for &'a mut Row {
+ type Item = &'a mut Cell;
+ type IntoIter = slice::IterMut<'a, Cell>;
+
+ fn into_iter(mut self) -> slice::IterMut<'a, Cell> {
+ self.iter_mut()
+ }
+}
+
impl Deref for Row {
type Target = Vec<Cell>;
fn deref(&self) -> &Self::Target {
@@ -295,7 +314,7 @@ macro_rules! clear_region_impl {
impl ClearRegion<$range> for Grid {
fn clear_region(&mut self, region: $range) {
for row in self.raw[region].iter_mut() {
- for cell in row.iter_mut() {
+ for cell in row {
cell.reset();
}
}
diff --git a/src/term.rs b/src/term.rs
index 3ffe9c47..699df8de 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -505,7 +505,7 @@ impl ansi::Handler for Term {
ansi::LineClearMode::Right => {
let row = &mut self.grid[self.cursor.y as usize];
let start = self.cursor.x as usize;
- for cell in row[start..].iter_mut() {
+ for cell in &mut row[start..] {
cell.reset();
}
},
@@ -520,8 +520,8 @@ impl ansi::Handler for Term {
let end = self.grid.num_rows();
for i in start..end {
let row = &mut self.grid[i];
- for cell in row.iter_mut() {
- cell.c = ' ';
+ for cell in row {
+ cell.reset();
}
}
},