Skip to content

Commit

Permalink
refactor: apply clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
metent committed Dec 2, 2024
1 parent 9ce4b2f commit f579c8c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
profile: minimal
toolchain: stable
override: true
- name: Lint
run: cargo clippy --all-targets
- name: Format
run: cargo fmt --check
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion src/bin/uair/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl AppData {
let mut stream = self.listener.listen().await?;
buffer.clear();
let msg = stream.read(&mut buffer).await?;
let command: Command = bincode::deserialize(&msg)?;
let command: Command = bincode::deserialize(msg)?;
match command {
Command::Pause(_) | Command::Toggle(_) if R => {
return Ok(Event::Command(Command::Pause(PauseArgs {})))
Expand Down
6 changes: 3 additions & 3 deletions src/bin/uair/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl SessionBuilder {
Session {
id: self.id.unwrap_or_else(|| idx.to_string()),
name: self.name.unwrap_or_else(|| defaults.name.clone()),
duration: self.duration.unwrap_or_else(|| defaults.duration.clone()),
duration: self.duration.unwrap_or(defaults.duration),
command: self.command.unwrap_or_else(|| defaults.command.clone()),
format: self
.format
Expand All @@ -173,9 +173,9 @@ impl SessionBuilder {
time_format: TimeFormatToken::parse(
self.time_format
.as_ref()
.unwrap_or_else(|| &defaults.time_format),
.unwrap_or(&defaults.time_format),
),
autostart: self.autostart.unwrap_or_else(|| defaults.autostart.clone()),
autostart: self.autostart.unwrap_or(defaults.autostart),
paused_state_text: self
.paused_state_text
.unwrap_or_else(|| defaults.paused_state_text.clone()),
Expand Down
8 changes: 4 additions & 4 deletions src/bin/uair/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use uair::get_socket_path;
fn main() -> ExitCode {
let args: Args = argh::from_env();
if args.version {
_ = write!(
_ = writeln!(
io::stdout(),
"{} version {}\n",
"{} version {}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
);
Expand Down Expand Up @@ -48,7 +48,7 @@ fn main() -> ExitCode {
}
}

return ExitCode::SUCCESS;
ExitCode::SUCCESS
}

#[derive(FromArgs)]
Expand Down Expand Up @@ -86,7 +86,7 @@ fn get_config_path() -> String {
}

async fn catch_term_signals() -> Result<(), Error> {
let mut signals = Signals::new(&[SIGTERM, SIGINT, SIGQUIT])?;
let mut signals = Signals::new([SIGTERM, SIGINT, SIGQUIT])?;
signals.next().await;
Ok(())
}
Expand Down
24 changes: 12 additions & 12 deletions src/bin/uair/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl Session {
format: overrid
.and_then(|o| o.format.as_ref())
.unwrap_or(&self.format),
pst_override: overrid.and_then(|o| o.paused_state_text.as_ref().map(|s| s.as_str())),
rst_override: overrid.and_then(|o| o.resumed_state_text.as_ref().map(|s| s.as_str())),
pst_override: overrid.and_then(|o| o.paused_state_text.as_deref()),
rst_override: overrid.and_then(|o| o.resumed_state_text.as_deref()),
}
}

Expand Down Expand Up @@ -109,15 +109,15 @@ impl<'s, const R: bool> Display for DisplayableSession<'s, R> {
self.pst_override.unwrap_or(&self.session.paused_state_text)
}
)?,
Token::Color(Color::Black) => write!(f, "{}", "\x1b[0;30m")?,
Token::Color(Color::Red) => write!(f, "{}", "\x1b[0;31m")?,
Token::Color(Color::Green) => write!(f, "{}", "\x1b[0;32m")?,
Token::Color(Color::Yellow) => write!(f, "{}", "\x1b[0;33m")?,
Token::Color(Color::Blue) => write!(f, "{}", "\x1b[0;34m")?,
Token::Color(Color::Purple) => write!(f, "{}", "\x1b[0;35m")?,
Token::Color(Color::Cyan) => write!(f, "{}", "\x1b[0;36m")?,
Token::Color(Color::White) => write!(f, "{}", "\x1b[0;37m")?,
Token::Color(Color::End) => write!(f, "{}", "\x1b[0m")?,
Token::Color(Color::Black) => write!(f, "\x1b[0;30m")?,
Token::Color(Color::Red) => write!(f, "\x1b[0;31m")?,
Token::Color(Color::Green) => write!(f, "\x1b[0;32m")?,
Token::Color(Color::Yellow) => write!(f, "\x1b[0;33m")?,
Token::Color(Color::Blue) => write!(f, "\x1b[0;34m")?,
Token::Color(Color::Purple) => write!(f, "\x1b[0;35m")?,
Token::Color(Color::Cyan) => write!(f, "\x1b[0;36m")?,
Token::Color(Color::White) => write!(f, "\x1b[0;37m")?,
Token::Color(Color::End) => write!(f, "\x1b[0m")?,
Token::Literal(literal) => write!(f, "{}", literal)?,
};
}
Expand Down Expand Up @@ -203,7 +203,7 @@ impl Token {
'{' => open = Some(i),
'}' => {
if let Some(j) = open {
if let Ok(token) = (&format[j..=i]).parse() {
if let Ok(token) = format[j..=i].parse() {
if k != j {
tokens.push(Token::Literal(format[k..j].into()))
};
Expand Down
12 changes: 6 additions & 6 deletions src/bin/uairctl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use uair::{get_socket_path, Command, FetchArgs};
fn main() -> Result<(), Error> {
let mut args: Args = argh::from_env();
if let Command::Fetch(FetchArgs { format }) = &mut args.command {
*format = unescape(&format);
*format = unescape(format);
}

let command = bincode::serialize(&args.command)?;
Expand Down Expand Up @@ -66,7 +66,7 @@ fn unescape(input: &str) -> String {
}
}
match u32::from_str_radix(&input[i + 1..i + 5], 16)
.map(|num| char::from_u32(num))
.map(char::from_u32)
{
Ok(Some(num)) => res.push(num),
_ => res.push_str(&input[i - 1..i + 5]),
Expand All @@ -80,7 +80,7 @@ fn unescape(input: &str) -> String {
}
}
match u32::from_str_radix(&input[i + 1..i + 9], 16)
.map(|num| char::from_u32(num))
.map(char::from_u32)
{
Ok(Some(num)) => res.push(num),
_ => res.push_str(&input[i - 1..i + 9]),
Expand Down Expand Up @@ -111,11 +111,11 @@ struct Args {
#[derive(thiserror::Error, Debug)]
enum Error {
#[error("Serialization Error: {0}")]
SerError(#[from] bincode::Error),
Ser(#[from] bincode::Error),
#[error("Socket Connection Error: {0}")]
IoError(#[from] io::Error),
Io(#[from] io::Error),
#[error("UTF8 Error: {0}")]
Utf8Error(#[from] str::Utf8Error),
Utf8(#[from] str::Utf8Error),
}

#[cfg(test)]
Expand Down

0 comments on commit f579c8c

Please sign in to comment.