mirror of
https://github.com/NotAShelf/stash.git
synced 2026-04-13 06:23:47 +00:00
stash: refactor error handling and entry deduplication
This includes breaking changes to the database entries, where we have started deduplicating based on hashes instead of full entries. Entry collisions are possible, but highly unlikely. Additionally we use `Box<str>` for error variants to reduce allocations. This is *yet* to give me a non-marginal performance benefit but doesn't hurt to be more correct. Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6a6a6964d0a33392da61372214ca3088551564ac
This commit is contained in:
parent
d05ad311a9
commit
a41d72fb6b
7 changed files with 348 additions and 258 deletions
|
|
@ -26,7 +26,7 @@ impl DecodeCommand for SqliteClipboardDb {
|
|||
let mut buf = String::new();
|
||||
in_
|
||||
.read_to_string(&mut buf)
|
||||
.map_err(|e| StashError::DecodeRead(e.to_string()))?;
|
||||
.map_err(|e| StashError::DecodeRead(e.to_string().into()))?;
|
||||
buf
|
||||
};
|
||||
|
||||
|
|
@ -38,18 +38,18 @@ impl DecodeCommand for SqliteClipboardDb {
|
|||
{
|
||||
let mut buf = Vec::new();
|
||||
reader.read_to_end(&mut buf).map_err(|e| {
|
||||
StashError::DecodeRead(format!(
|
||||
"Failed to read clipboard for relay: {e}"
|
||||
))
|
||||
StashError::DecodeRead(
|
||||
format!("Failed to read clipboard for relay: {e}").into(),
|
||||
)
|
||||
})?;
|
||||
out.write_all(&buf).map_err(|e| {
|
||||
StashError::DecodeWrite(format!(
|
||||
"Failed to write clipboard relay: {e}"
|
||||
))
|
||||
StashError::DecodeWrite(
|
||||
format!("Failed to write clipboard relay: {e}").into(),
|
||||
)
|
||||
})?;
|
||||
} else {
|
||||
return Err(StashError::DecodeGet(
|
||||
"Failed to get clipboard contents for relay".to_string(),
|
||||
"Failed to get clipboard contents for relay".into(),
|
||||
));
|
||||
}
|
||||
return Ok(());
|
||||
|
|
@ -69,14 +69,14 @@ impl DecodeCommand for SqliteClipboardDb {
|
|||
{
|
||||
let mut buf = Vec::new();
|
||||
reader.read_to_end(&mut buf).map_err(|err| {
|
||||
StashError::DecodeRead(format!(
|
||||
"Failed to read clipboard for relay: {err}"
|
||||
))
|
||||
StashError::DecodeRead(
|
||||
format!("Failed to read clipboard for relay: {err}").into(),
|
||||
)
|
||||
})?;
|
||||
out.write_all(&buf).map_err(|err| {
|
||||
StashError::DecodeWrite(format!(
|
||||
"Failed to write clipboard relay: {err}"
|
||||
))
|
||||
StashError::DecodeWrite(
|
||||
format!("Failed to write clipboard relay: {err}").into(),
|
||||
)
|
||||
})?;
|
||||
Ok(())
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue