treewide: format with rustfmt

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69642c2865f41a4b141ddf39a198a3fc2e09
This commit is contained in:
raf 2025-08-20 09:40:20 +03:00
commit 6a5cd9b95d
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
10 changed files with 1191 additions and 1132 deletions

View file

@ -1,75 +1,78 @@
use crate::db::{ClipboardDb, SqliteClipboardDb};
use std::io::{Read, Write};
use crate::db::StashError;
use wl_clipboard_rs::paste::{ClipboardType, MimeType, Seat, get_contents};
use crate::db::{ClipboardDb, SqliteClipboardDb, StashError};
pub trait DecodeCommand {
fn decode(
&self,
in_: impl Read,
out: impl Write,
input: Option<String>,
) -> Result<(), StashError>;
fn decode(
&self,
in_: impl Read,
out: impl Write,
input: Option<String>,
) -> Result<(), StashError>;
}
impl DecodeCommand for SqliteClipboardDb {
fn decode(
&self,
mut in_: impl Read,
mut out: impl Write,
input: Option<String>,
) -> Result<(), StashError> {
let input_str = if let Some(s) = input {
s
fn decode(
&self,
mut in_: impl Read,
mut out: impl Write,
input: Option<String>,
) -> Result<(), StashError> {
let input_str = if let Some(s) = input {
s
} else {
let mut buf = String::new();
if let Err(e) = in_.read_to_string(&mut buf) {
log::error!("Failed to read stdin for decode: {e}");
}
buf
};
// If input is empty or whitespace, treat as error and trigger fallback
if input_str.trim().is_empty() {
log::info!("No input provided to decode; relaying clipboard to stdout");
if let Ok((mut reader, _mime)) =
get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Any)
{
let mut buf = Vec::new();
if let Err(err) = reader.read_to_end(&mut buf) {
log::error!("Failed to read clipboard for relay: {err}");
} else {
let mut buf = String::new();
if let Err(e) = in_.read_to_string(&mut buf) {
log::error!("Failed to read stdin for decode: {e}");
}
buf
};
// If input is empty or whitespace, treat as error and trigger fallback
if input_str.trim().is_empty() {
log::info!("No input provided to decode; relaying clipboard to stdout");
if let Ok((mut reader, _mime)) =
get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Any)
{
let mut buf = Vec::new();
if let Err(err) = reader.read_to_end(&mut buf) {
log::error!("Failed to read clipboard for relay: {err}");
} else {
let _ = out.write_all(&buf);
}
} else {
log::error!("Failed to get clipboard contents for relay");
}
return Ok(());
let _ = out.write_all(&buf);
}
// Try decode as usual
match self.decode_entry(input_str.as_bytes(), &mut out, Some(input_str.clone())) {
Ok(()) => {
log::info!("Entry decoded");
}
Err(e) => {
log::error!("Failed to decode entry: {e}");
if let Ok((mut reader, _mime)) =
get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Any)
{
let mut buf = Vec::new();
if let Err(err) = reader.read_to_end(&mut buf) {
log::error!("Failed to read clipboard for relay: {err}");
} else {
let _ = out.write_all(&buf);
}
} else {
log::error!("Failed to get clipboard contents for relay");
}
}
}
Ok(())
} else {
log::error!("Failed to get clipboard contents for relay");
}
return Ok(());
}
// Try decode as usual
match self.decode_entry(
input_str.as_bytes(),
&mut out,
Some(input_str.clone()),
) {
Ok(()) => {
log::info!("Entry decoded");
},
Err(e) => {
log::error!("Failed to decode entry: {e}");
if let Ok((mut reader, _mime)) =
get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Any)
{
let mut buf = Vec::new();
if let Err(err) = reader.read_to_end(&mut buf) {
log::error!("Failed to read clipboard for relay: {err}");
} else {
let _ = out.write_all(&buf);
}
} else {
log::error!("Failed to get clipboard contents for relay");
}
},
}
Ok(())
}
}