diff options
Diffstat (limited to 'src/utils.rs')
-rw-r--r-- | src/utils.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/utils.rs b/src/utils.rs index 8f4bbf3..c00b2d7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -30,12 +30,12 @@ impl StringWriter { impl Write for StringWriter { fn write(&mut self, data: &[u8]) -> Result<usize, Error> { - let string = match str::from_utf8(data) {
- Ok(s) => s,
+ let string = match str::from_utf8(data) { + Ok(s) => s, Err(e) => { return Err(Error::new(ErrorKind::Other, format!("Cannot decode utf8 string : {}", e))) - }
+ } }; self.string.push_str(string); Ok(data.len()) @@ -59,18 +59,18 @@ pub fn print_align<T: Write + ?Sized>(out: &mut T, -> Result<(), Error> { let text_len = UnicodeWidthStr::width(text); let mut nfill = if text_len < size { size - text_len } else { 0 }; - let n = match align {
- Alignment::LEFT => 0,
- Alignment::RIGHT => nfill,
- Alignment::CENTER => nfill / 2,
+ let n = match align { + Alignment::LEFT => 0, + Alignment::RIGHT => nfill, + Alignment::CENTER => nfill / 2, }; if n > 0 { - try!(out.write(&vec![fill as u8; n])); + try!(out.write_all(&vec![fill as u8; n])); nfill -= n; } - try!(out.write(text.as_bytes())); + try!(out.write_all(text.as_bytes())); if nfill > 0 && !skip_right_fill { - try!(out.write(&vec![fill as u8; nfill])); + try!(out.write_all(&vec![fill as u8; nfill])); } Ok(()) } |