From 60404db64e2f0234ac38dc41ba221d358c033c86 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Mar 2023 00:17:04 +0000 Subject: [PATCH] simplified error handling with custom result type --- src/lib.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5ba1afd..e72d09a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,13 +4,14 @@ mod ipc; use std::os::unix::net::UnixStream; use std::io::prelude::*; -use std::io::Result; use serde::de::DeserializeOwned; use i3msg::I3msg; use types::*; use ipc::*; +type Result = std::result::Result>; + pub struct Sway { stream: UnixStream, } @@ -107,17 +108,11 @@ impl Sway { let mut buffer = [0; 25000]; let n = self.stream.read(&mut buffer)?; - match serde_json::from_slice::(&buffer[14..n]) { - Ok(result) => Ok(result), - Err(e) => Err(e.into()), - } + Ok(serde_json::from_slice::(&buffer[14..n])?) } fn parse_events(&mut self, events: Vec<&str>) -> Result { - match serde_json::to_string(&events) { - Ok(json) => Ok(json), - Err(e) => Err(e.into()), - } + Ok(serde_json::to_string(&events)?) } }