From 2995f6e48b334088dbc4935e0cd8e3a09563f61d Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Feb 2023 03:27:36 +0000 Subject: [PATCH] error handling cleanup --- src/i3msg.rs | 6 ++---- src/lib.rs | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/i3msg.rs b/src/i3msg.rs index 9b3ad32..ec8c617 100644 --- a/src/i3msg.rs +++ b/src/i3msg.rs @@ -29,9 +29,7 @@ impl<'payload> I3msg<'payload> { IoSlice::new(self.payload.as_bytes()), ]; - match self.buffer.write_vectored(bufs) { - Ok(_) => return Ok(self.buffer.to_owned()), - Err(e) => return Err(e), - } + self.buffer.write_vectored(bufs)?; + Ok(self.buffer.to_owned()) } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 327ba56..3ab313b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,10 +17,8 @@ pub struct Sway { impl Sway { pub fn new(socket: &str) -> Result { - match UnixStream::connect(socket) { - Ok(stream) => return Ok(Sway{stream}), - Err(e) => return Err(e), - }; + let stream = UnixStream::connect(socket)?; + Ok(Sway{stream}) } /// Runs the payload as sway commands @@ -126,7 +124,7 @@ impl Sway { #[cfg(test)] mod tests { use crate::Sway; - use crate::i3msg::*; + use crate::i3msg::I3msg; use crate::ipc::*; fn sway_ipc() -> Sway {