From 9341cc08e896eb7d249fd23ec2bf266a1324050b Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 28 Feb 2024 15:27:26 -0500 Subject: [PATCH] cleanup: prettier error handling --- src/lib.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 580833d..56e6c17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,16 +120,14 @@ impl Clipboard { { let _ = self.request_sender.send(worker::Command::Load(T::allowed().to_vec(), target)); - if let Ok(reply) = self.request_receiver.recv() { - match reply { - Ok((data, mime)) => T::try_from((data, mime)) - .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err)), - Err(err) => Err(err), - } - } else { - // The clipboard thread is dead, however we shouldn't crash downstream, so - // propogating an error. - Err(std::io::Error::new(std::io::ErrorKind::Other, "clipboard is dead.")) + match self.request_receiver.recv() { + Ok(res) => res.and_then(|(data, mime)| { + T::try_from((data, mime)) + .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err)) + }), + // The clipboard thread is dead, however we shouldn't crash downstream, + // so propogating an error. + Err(_) => Err(std::io::Error::new(std::io::ErrorKind::Other, "clipboard is dead.")), } }