diff options
author | William Brown <william@blackhats.net.au> | 2016-03-25 08:40:54 +1000 |
---|---|---|
committer | William Brown <william@blackhats.net.au> | 2016-03-25 08:40:54 +1000 |
commit | 16f0470dbc4496fe5b90de433a03b9ff5affcf8a (patch) | |
tree | 5180dd3329ec2455d3f919857b0d0bcd42f60ed3 | |
parent | 2d3ff462d8a5f584f5f25a4427ad766db37be5a1 (diff) |
Add some iters for use with rows to make formatting cells a bit easier
-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>
|