From 2d7fe699009d6f4010486cc27ccd0743f95a8ae9 Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Wed, 7 Jun 2017 23:38:14 +0200 Subject: Converted all try! macro uses to ? operator --- src/cell.rs | 4 ++-- src/format.rs | 10 +++++----- src/lib.rs | 30 +++++++++++++++--------------- src/row.rs | 18 +++++++++--------- src/utils.rs | 6 +++--- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/cell.rs b/src/cell.rs index 16ab37e..7155f43 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 25029f3..c5905f7 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) -> csv::Result> { 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>(csv_p: P) -> csv::Result { - 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 7bc5fa5..ceccfe5 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(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(()) } -- cgit v1.2.3