summaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-05 16:45:42 +0800
committersigoden <sigoden@gmail.com>2023-03-05 16:45:42 +0800
commit625f0343cbdc5a7bf11b649b98e239d9dcf53f6e (patch)
tree8fffbe1a36cbea637308f6d65cef8fde45fa0ee3 /src/utils.rs
parentbec8787a57821fd1fcc06b493f44e155fd7a7e84 (diff)
downloadaichat-625f0343cbdc5a7bf11b649b98e239d9dcf53f6e.tar.gz
chore: refactor error encapsulation
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/utils.rs b/src/utils.rs
index b248d92..5bc1237 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -9,14 +9,15 @@ pub fn dump<T: ToString>(text: T, newlines: usize) {
}
pub fn copy(src: &str) -> Result<()> {
- let mut ctx = ClipboardContext::new().map_err(|err| anyhow!("{err}"))?;
- ctx.set_contents(src.to_string())
- .map_err(|err| anyhow!("{err}"))
+ ClipboardContext::new()
+ .and_then(|mut ctx| ctx.set_contents(src.to_string()))
+ .map_err(|err| anyhow!("Failed to copy, {err}"))
}
pub fn paste() -> Result<String> {
- let mut ctx = ClipboardContext::new().map_err(|err| anyhow!("{err}"))?;
- ctx.get_contents().map_err(|err| anyhow!("{err}"))
+ ClipboardContext::new()
+ .and_then(|mut ctx| ctx.get_contents())
+ .map_err(|err| anyhow!("Failed to paste, {err}"))
}
pub fn now() -> String {