From daf595fe5648250c2947947ba5d9cdf4ab24b403 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 24 May 2020 15:52:35 +0200 Subject: stdio: nicer error handling --- safe_libc/src/stdio.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/safe_libc/src/stdio.rs b/safe_libc/src/stdio.rs index be016ab..2942405 100644 --- a/safe_libc/src/stdio.rs +++ b/safe_libc/src/stdio.rs @@ -7,6 +7,12 @@ pub struct Error { pub errno: errno::Errno, } +impl From for fmt::Error { + fn from(_err: Error) -> fmt::Error { + fmt::Error + } +} + pub type Result = core::result::Result; #[inline] @@ -58,9 +64,7 @@ impl BasicOStream { impl fmt::Write for BasicOStream { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { - if self.write(s.as_bytes()).is_err() { - return Err(fmt::Error); - } + self.write(s.as_bytes())?; Ok(()) } } -- cgit v1.2.3