From 96c7f145d91f707baf504ba3841d4e9a3039b7c0 Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Thu, 8 Aug 2024 14:59:05 +0200 Subject: [PATCH] better error handling --- src/main.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ddd085c..dac98fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,15 +22,22 @@ impl History { } fn update(&mut self) { - let clip = self.clipboard.get_text().unwrap(); - - for entry in &self.entries { - if &clip == entry { - return + let clipboard_result = self.clipboard.get_text(); + + match clipboard_result { + Ok(clipboard_content) => { + for entry in &self.entries { + if &clipboard_content == entry { + return + } + } + println!("new entry"); + self.entries.insert(0, clipboard_content); + } + Err(why) => { + eprintln!("could not fetch clipboard : {}", why); } } - println!("new entry"); - self.entries.insert(0, clip); } fn paste(&mut self) {