summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Henri Symoneaux <phsym@users.noreply.github.com>2017-06-08 08:50:15 +0200
committerGitHub <noreply@github.com>2017-06-08 08:50:15 +0200
commit91259572f46c6a890c547341e493a614c2443914 (patch)
tree2a13858424d0ceae135284537fa7b2f625055904
parentc5f20b362018aabb12608e220cf5b961621cc883 (diff)
parenta997815f81aa2fe864132a658974b1dc397c0324 (diff)
Merge pull request #64 from phsym/convert_try_macro_uses
Convert try macro uses
-rw-r--r--.travis.yml4
-rw-r--r--README.md3
-rw-r--r--src/cell.rs4
-rw-r--r--src/format.rs10
-rw-r--r--src/lib.rs30
-rw-r--r--src/row.rs18
-rw-r--r--src/utils.rs6
7 files changed, 36 insertions, 39 deletions
diff --git a/.travis.yml b/.travis.yml
index 734ba23..752a465 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,5 @@
language: rust
rust:
-- 1.9.0
-- 1.10.0
-- 1.11.0
-- 1.12.0
- 1.13.0
- 1.14.0
- 1.15.0
diff --git a/README.md b/README.md
index 8ea600e..333e5b9 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,8 @@ Include the library as a dependency to your project by adding the following line
prettytable-rs = "^0.6"
```
-The library requires at least `rust v1.9.0` in order to build
+The library requires at least `rust v1.9.0` in order to build,
+while `master` branch only builds starting from `rust v1.13.0`
## Basic usage
diff --git a/src/cell.rs b/src/cell.rs
index af70a9d..ec9deb7 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -201,7 +201,7 @@ impl Cell {
Err(e) => return Err(term_error_to_io_error(e)),
};
}
- try!(self.print(out, idx, col_width, skip_right_fill));
+ self.print(out, idx, col_width, skip_right_fill)?;
match out.reset() {
Ok(..) |
Err(::term::Error::NotSupported) |
@@ -376,7 +376,7 @@ mod tests {
.with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))
.with_style(Attr::BackgroundColor(color::WHITE));
cell.align(Alignment::RIGHT);
-
+
//style_spec("FDBwr");
assert_eq!(cell.style.len(), 2);
assert_eq!(cell.align, Alignment::RIGHT);
diff --git a/src/format.rs b/src/format.rs
index 6b83da7..5944f83 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -88,19 +88,19 @@ impl LineSeparator {
rborder: bool)
-> Result<(), Error> {
if lborder {
- try!(out.write_all(Utf8Char::from(self.ljunc).as_bytes()));
+ out.write_all(Utf8Char::from(self.ljunc).as_bytes())?;
}
let mut iter = col_width.into_iter().peekable();
while let Some(width) = iter.next() {
for _ in 0..width + padding.0 + padding.1 {
- try!(out.write_all(Utf8Char::from(self.line).as_bytes()));
+ out.write_all(Utf8Char::from(self.line).as_bytes())?;
}
if colsep && iter.peek().is_some() {
- try!(out.write_all(Utf8Char::from(self.junc).as_bytes()));
+ out.write_all(Utf8Char::from(self.junc).as_bytes())?;
}
}
if rborder {
- try!(out.write_all(Utf8Char::from(self.rjunc).as_bytes()));
+ out.write_all(Utf8Char::from(self.rjunc).as_bytes())?;
}
out.write_all(NEWLINE)
}
@@ -226,7 +226,7 @@ impl TableFormat {
match *self.get_sep_for_line(pos) {
Some(ref l) => {
//TODO: Wrap this into dedicated function one day
- try!(out.write_all(&vec![b' '; self.get_indent()]));
+ out.write_all(&vec![b' '; self.get_indent()])?;
l._print(out,
col_width,
self.get_padding(),
diff --git a/src/lib.rs b/src/lib.rs
index df84fbe..b031255 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -140,24 +140,24 @@ impl<'a> TableSlice<'a> {
{
// Compute columns width
let col_width = self.get_all_column_width();
- try!(self.format
- .print_line_separator(out, &col_width, LinePosition::Top));
+ self.format
+ .print_line_separator(out, &col_width, LinePosition::Top)?;
if let Some(ref t) = *self.titles {
- try!(f(t, out, self.format, &col_width));
- try!(self.format
- .print_line_separator(out, &col_width, LinePosition::Title));
+ f(t, out, self.format, &col_width)?;
+ self.format
+ .print_line_separator(out, &col_width, LinePosition::Title)?;
}
// Print rows
let mut iter = self.rows.into_iter().peekable();
while let Some(r) = iter.next() {
- try!(f(r, out, self.format, &col_width));
+ f(r, out, self.format, &col_width)?;
if iter.peek().is_some() {
- try!(self.format
- .print_line_separator(out, &col_width, LinePosition::Intern));
+ self.format
+ .print_line_separator(out, &col_width, LinePosition::Intern)?;
}
}
- try!(self.format
- .print_line_separator(out, &col_width, LinePosition::Bottom));
+ self.format
+ .print_line_separator(out, &col_width, LinePosition::Bottom)?;
out.flush()
}
@@ -214,13 +214,13 @@ impl<'a> TableSlice<'a> {
mut writer: csv::Writer<W>)
-> csv::Result<csv::Writer<W>> {
for title in self.titles {
- try!(writer.write(title.iter().map(|c| c.get_content())));
+ writer.write(title.iter().map(|c| c.get_content()))?;
}
for row in self.rows {
- try!(writer.write(row.iter().map(|c| c.get_content())));
+ writer.write(row.iter().map(|c| c.get_content()))?;
}
- try!(writer.flush());
+ writer.flush()?;
Ok(writer)
}
}
@@ -261,7 +261,7 @@ impl Table {
/// For more customisability use `from_csv()`
#[cfg(feature = "csv")]
pub fn from_csv_file<P: AsRef<Path>>(csv_p: P) -> csv::Result<Table> {
- Ok(Table::from_csv(&mut try!(csv::Reader::from_file(csv_p)).has_headers(false)))
+ Ok(Table::from_csv(&mut csv::Reader::from_file(csv_p)?.has_headers(false)))
}
/// Create a table from a CSV reader
@@ -349,7 +349,7 @@ impl Table {
/// Modify a single element in the table
pub fn set_element(&mut self, element: &str, column: usize, row: usize) -> Result<(), &str> {
- let rowline = try!(self.get_mut_row(row).ok_or("Cannot find row"));
+ let rowline = self.get_mut_row(row).ok_or("Cannot find row")?;
// TODO: If a cell already exist, copy it's alignment parameter
rowline.set_cell(Cell::new(element), column)
}
diff --git a/src/row.rs b/src/row.rs
index 47498dd..2dfcc73 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -120,24 +120,24 @@ impl Row {
{
for i in 0..self.get_height() {
//TODO: Wrap this into dedicated function one day
- try!(out.write_all(&vec![b' '; format.get_indent()]));
- try!(format.print_column_separator(out, ColumnPosition::Left));
+ out.write_all(&vec![b' '; format.get_indent()])?;
+ format.print_column_separator(out, ColumnPosition::Left)?;
let (lp, rp) = format.get_padding();
for j in 0..col_width.len() {
- try!(out.write_all(&vec![b' '; lp]));
+ out.write_all(&vec![b' '; lp])?;
let skip_r_fill = (j == col_width.len() - 1) &&
format.get_column_separator(ColumnPosition::Right).is_none();
match self.get_cell(j) {
- Some(c) => try!(f(c, out, i, col_width[j], skip_r_fill)),
- None => try!(f(&Cell::default(), out, i, col_width[j], skip_r_fill)),
+ Some(c) => f(c, out, i, col_width[j], skip_r_fill)?,
+ None => f(&Cell::default(), out, i, col_width[j], skip_r_fill)?,
};
- try!(out.write_all(&vec![b' '; rp]));
+ out.write_all(&vec![b' '; rp])?;
if j < col_width.len() - 1 {
- try!(format.print_column_separator(out, ColumnPosition::Intern));
+ format.print_column_separator(out, ColumnPosition::Intern)?;
}
}
- try!(format.print_column_separator(out, ColumnPosition::Right));
- try!(out.write_all(NEWLINE));
+ format.print_column_separator(out, ColumnPosition::Right)?;
+ out.write_all(NEWLINE)?;
}
Ok(())
}
diff --git a/src/utils.rs b/src/utils.rs
index a9da33b..b96828e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -65,12 +65,12 @@ pub fn print_align<T: Write + ?Sized>(out: &mut T,
Alignment::CENTER => nfill / 2,
};
if n > 0 {
- try!(out.write_all(&vec![fill as u8; n]));
+ out.write_all(&vec![fill as u8; n])?;
nfill -= n;
}
- try!(out.write_all(text.as_bytes()));
+ out.write_all(text.as_bytes())?;
if nfill > 0 && !skip_right_fill {
- try!(out.write_all(&vec![fill as u8; nfill]));
+ out.write_all(&vec![fill as u8; nfill])?;
}
Ok(())
}