Skip to content

Commit 152d00a

Browse files
committed
Cargo fmt and clippy fix
1 parent 58a9b21 commit 152d00a

File tree

9 files changed

+51
-32
lines changed

9 files changed

+51
-32
lines changed

burnt-sushi/src/blocker.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl SpotifyHookState {
8888

8989
match spotify.process.pid().ok() {
9090
Some(pid) => info!("Found Spotify (PID={pid})"),
91-
None => info!("Found Spotify")
91+
None => info!("Found Spotify"),
9292
}
9393
let syringe = Syringe::for_process(spotify.process);
9494

@@ -116,7 +116,7 @@ impl SpotifyHookState {
116116
info!("Ejecting previous blocker...");
117117
match syringe.eject(prev_payload) {
118118
Ok(_) => info!("Ejected previous blocker"),
119-
Err(_) => error!("Failed to eject previous blocker")
119+
Err(_) => error!("Failed to eject previous blocker"),
120120
};
121121
}
122122

@@ -131,7 +131,8 @@ impl SpotifyHookState {
131131
.context("Failed to resolve blocker.")?;
132132

133133
info!("Injecting blocker...");
134-
let payload = syringe.inject(payload_path)
134+
let payload = syringe
135+
.inject(payload_path)
135136
.context("Failed to inject blocker.")?;
136137

137138
debug!("Starting RPC...");

burnt-sushi/src/logger/console/log.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use winapi::{
2323
},
2424
};
2525

26-
use crate::{APP_NAME_WITH_VERSION, logger::SimpleLog};
26+
use crate::{logger::SimpleLog, APP_NAME_WITH_VERSION};
2727

2828
use super::raw;
2929

@@ -34,10 +34,7 @@ pub struct Console(ConsoleImpl);
3434
enum ConsoleImpl {
3535
Attach,
3636
Alloc,
37-
Piped {
38-
process: OwnedProcess,
39-
pipe: File,
40-
},
37+
Piped { process: OwnedProcess, pipe: File },
4138
}
4239

4340
unsafe impl Send for Console {}

burnt-sushi/src/logger/file.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#![allow(dead_code)]
22

33
use std::{
4-
fs::{File, self},
5-
io::{Write, BufWriter, Read, SeekFrom, Seek},
6-
path::PathBuf, time::Instant,
4+
fs::{self, File},
5+
io::{BufWriter, Read, Seek, SeekFrom, Write},
6+
path::PathBuf,
7+
time::Instant,
78
};
89

910
use anyhow::Context;
@@ -14,15 +15,15 @@ use super::SimpleLog;
1415
pub struct FileLog {
1516
path: PathBuf,
1617
file: Option<BufWriter<File>>,
17-
last_written: Option<Instant>
18+
last_written: Option<Instant>,
1819
}
1920

2021
impl FileLog {
2122
pub fn new(path: impl Into<PathBuf>) -> Self {
2223
Self {
2324
path: path.into(),
2425
file: None,
25-
last_written: None
26+
last_written: None,
2627
}
2728
}
2829

@@ -34,26 +35,37 @@ impl FileLog {
3435
if let Some(dir) = self.path.parent() {
3536
fs::create_dir_all(dir).context("Failed to create parent directories for log file.")?;
3637
}
37-
let mut file = File::options().create(true).append(true).open(&self.path).context("Failed to open or create log file.")?;
38-
38+
let mut file = File::options()
39+
.create(true)
40+
.append(true)
41+
.open(&self.path)
42+
.context("Failed to open or create log file.")?;
43+
3944
dbg!();
4045
if dbg!(dbg!(file.metadata().unwrap().len()) > 100 * 1024) {
41-
file = File::options().write(true).read(true).open(&self.path).context("Failed to open or create log file.")?;
46+
file = File::options()
47+
.write(true)
48+
.read(true)
49+
.open(&self.path)
50+
.context("Failed to open or create log file.")?;
4251
let mut contents = String::new();
43-
file.read_to_string(&mut contents).context("Failed to read log file.")?;
52+
file.read_to_string(&mut contents)
53+
.context("Failed to read log file.")?;
4454

4555
let mut truncated_contents = String::new();
4656
for (index, _) in contents.match_indices('\n') {
47-
let succeeding = &contents[(index+1)..];
57+
let succeeding = &contents[(index + 1)..];
4858
if succeeding.len() > 10 * 1024 {
4959
continue;
5060
}
5161
truncated_contents.push_str(succeeding);
5262
break;
5363
}
54-
file.seek(SeekFrom::Start(0)).context("Failed to seek in log file.")?;
64+
file.seek(SeekFrom::Start(0))
65+
.context("Failed to seek in log file.")?;
5566
file.set_len(0).context("Failed to clear log file.")?;
56-
file.write_all(truncated_contents.as_bytes()).context("Failed to write log file.")?;
67+
file.write_all(truncated_contents.as_bytes())
68+
.context("Failed to write log file.")?;
5769
}
5870
let writer = BufWriter::new(file);
5971
Ok(self.file.insert(writer))
@@ -62,7 +74,10 @@ impl FileLog {
6274

6375
impl SimpleLog for FileLog {
6476
fn log(&mut self, message: &str) {
65-
let file = self.open_file().context("Failed to prepare log file.").unwrap();
77+
let file = self
78+
.open_file()
79+
.context("Failed to prepare log file.")
80+
.unwrap();
6681
writeln!(file, "{}", message).unwrap();
6782
file.flush().unwrap();
6883
}

burnt-sushi/src/logger/global.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use std::{sync::{Mutex, MutexGuard}, fmt::Debug};
1+
use std::{
2+
fmt::Debug,
3+
sync::{Mutex, MutexGuard},
4+
};
25

36
use log::Log;
47

58
use crate::APP_NAME;
69

7-
use super::{SimpleLog, Console, FileLog};
8-
10+
use super::{Console, FileLog, SimpleLog};
911

1012
static LOGGER: GlobalLoggerHolder = GlobalLoggerHolder(Mutex::new(GlobalLogger::new()));
1113

@@ -37,12 +39,11 @@ impl GlobalLogger {
3739
pub const fn new() -> Self {
3840
GlobalLogger {
3941
console: None,
40-
file: None
42+
file: None,
4143
}
4244
}
4345
}
4446

45-
4647
impl Log for GlobalLoggerHolder {
4748
fn enabled(&self, _metadata: &log::Metadata) -> bool {
4849
true

burnt-sushi/src/logger/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
pub mod global;
21
pub mod console;
32
pub mod file;
3+
pub mod global;
44
pub mod noop;
55

66
mod traits;
77

8-
pub use traits::*;
98
pub use console::Console;
109
pub use file::FileLog;
10+
pub use traits::*;

burnt-sushi/src/logger/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt::Debug, any::Any};
1+
use std::{any::Any, fmt::Debug};
22

33
pub trait SimpleLog: Any + Debug + Send + Sync {
44
fn log(&mut self, message: &str);

burnt-sushi/src/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ use winapi::{
2020

2121
use std::{env, io, os::windows::prelude::FromRawHandle, time::Duration};
2222

23-
use crate::{args::{ARGS, LogLevel}, blocker::SpotifyAdBlocker, named_mutex::NamedMutex, logger::{Console, FileLog}};
23+
use crate::{
24+
args::{LogLevel, ARGS},
25+
blocker::SpotifyAdBlocker,
26+
logger::{Console, FileLog},
27+
named_mutex::NamedMutex,
28+
};
2429

2530
mod args;
2631
mod blocker;

burnt-sushi/src/tray.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl SystemTrayIcon {
121121

122122
fn show_console(&self) {
123123
let mut l = logger::global::get();
124-
if !l.console.is_some() {
124+
if l.console.is_none() {
125125
l.console = Some(Console::piped().unwrap());
126126
}
127127
}

shared/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod rpc {
1212
pub use super::spotify_ad_guard_capnp::*;
1313
}
1414

15-
#[allow(clippy::derive_hash_xor_eq)]
15+
#[allow(clippy::derived_hash_with_manual_eq)]
1616
impl hash::Hash for rpc::blocker_service::FilterHook {
1717
fn hash<H: hash::Hasher>(&self, state: &mut H) {
1818
core::mem::discriminant(self).hash(state)

0 commit comments

Comments
 (0)