diff options
-rw-r--r-- | src/lib.rs | 10 | ||||
-rw-r--r-- | src/row.rs | 11 |
2 files changed, 21 insertions, 0 deletions
@@ -10,6 +10,7 @@ use std::io; use std::io::{Write, Error};
use std::fmt;
use std::iter::{FromIterator, IntoIterator};
+use std::slice::{Iter, IterMut}; use std::ops::{Index, IndexMut};
use std::mem::transmute;
@@ -273,6 +274,15 @@ impl Table { pub fn column_iter_mut(&mut self, column: usize) -> ColumnIterMut {
return ColumnIterMut(self.rows.iter_mut(), column);
}
+ + pub fn row_iter<'a>(&'a self) -> Iter<'a, Row> { + self.rows.iter() + } + + pub fn row_iter_mut<'a>(&'a mut self) -> IterMut<'a, Row> { + self.rows.iter_mut() + } + /// Print the table to `out`
pub fn print<T: Write+?Sized>(&self, out: &mut T) -> Result<(), Error> {
@@ -1,6 +1,7 @@ //! This module contains definition of table rows stuff
use std::io::{Write, Error};
use std::iter::FromIterator;
+use std::slice::{Iter, IterMut};
use std::ops::{Index, IndexMut};
use term::Terminal;
@@ -95,6 +96,16 @@ impl Row { }
}
+ // You need to impl Iterator for these to work with for / map implicitly
+ // But there is a compiler warning when you do add the trait.
+ pub fn iter<'a>(&'a self) -> Iter<'a, Cell> {
+ self.cells.iter()
+ }
+
+ pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Cell> {
+ self.cells.iter_mut()
+ }
+
/// Internal only
fn __print<T:Write+?Sized, F>(&self, out: &mut T, format: &TableFormat, col_width: &[usize], f: F) -> Result<(), Error>
where F: Fn(&Cell, &mut T, usize, usize, bool) -> Result<(), Error>
|