Skip to content

Commit 9bd4c9a

Browse files
committed
treewide: format with nightly rustfmt rules
Signed-off-by: NotAShelf <[email protected]> Change-Id: Ib8502372dafe2e970024f606b44825af6a6a6964
1 parent af8031f commit 9bd4c9a

File tree

6 files changed

+219
-202
lines changed

6 files changed

+219
-202
lines changed

benches/benchmark.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
use criterion::{Criterion, criterion_group, criterion_main};
2-
use microfetch_lib::colors::print_dots;
3-
use microfetch_lib::desktop::get_desktop_info;
4-
use microfetch_lib::release::{get_os_pretty_name, get_system_info};
5-
use microfetch_lib::system::{
6-
get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname,
2+
use microfetch_lib::{
3+
colors::print_dots,
4+
desktop::get_desktop_info,
5+
release::{get_os_pretty_name, get_system_info},
6+
system::{
7+
get_memory_usage,
8+
get_root_disk_usage,
9+
get_shell,
10+
get_username_and_hostname,
11+
},
12+
uptime::get_current,
713
};
8-
use microfetch_lib::uptime::get_current;
914

1015
fn main_benchmark(c: &mut Criterion) {
11-
let utsname = nix::sys::utsname::uname().expect("lol");
12-
c.bench_function("user_info", |b| {
13-
b.iter(|| get_username_and_hostname(&utsname));
14-
});
15-
c.bench_function("os_name", |b| b.iter(get_os_pretty_name));
16-
c.bench_function("kernel_version", |b| b.iter(|| get_system_info(&utsname)));
17-
c.bench_function("shell", |b| b.iter(get_shell));
16+
let utsname = nix::sys::utsname::uname().expect("lol");
17+
c.bench_function("user_info", |b| {
18+
b.iter(|| get_username_and_hostname(&utsname));
19+
});
20+
c.bench_function("os_name", |b| b.iter(get_os_pretty_name));
21+
c.bench_function("kernel_version", |b| b.iter(|| get_system_info(&utsname)));
22+
c.bench_function("shell", |b| b.iter(get_shell));
1823

19-
c.bench_function("desktop", |b| b.iter(get_desktop_info));
20-
c.bench_function("uptime", |b| b.iter(get_current));
21-
c.bench_function("memory_usage", |b| b.iter(get_memory_usage));
22-
c.bench_function("storage", |b| b.iter(get_root_disk_usage));
23-
c.bench_function("colors", |b| b.iter(print_dots));
24+
c.bench_function("desktop", |b| b.iter(get_desktop_info));
25+
c.bench_function("uptime", |b| b.iter(get_current));
26+
c.bench_function("memory_usage", |b| b.iter(get_memory_usage));
27+
c.bench_function("storage", |b| b.iter(get_root_disk_usage));
28+
c.bench_function("colors", |b| b.iter(print_dots));
2429
}
2530

2631
criterion_group!(benches, main_benchmark);

src/colors.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
use std::env;
2-
use std::sync::LazyLock;
1+
use std::{env, sync::LazyLock};
32

43
pub struct Colors {
5-
pub reset: &'static str,
6-
pub blue: &'static str,
7-
pub cyan: &'static str,
8-
pub green: &'static str,
9-
pub yellow: &'static str,
10-
pub red: &'static str,
11-
pub magenta: &'static str,
4+
pub reset: &'static str,
5+
pub blue: &'static str,
6+
pub cyan: &'static str,
7+
pub green: &'static str,
8+
pub yellow: &'static str,
9+
pub red: &'static str,
10+
pub magenta: &'static str,
1211
}
1312

1413
impl Colors {
15-
const fn new(is_no_color: bool) -> Self {
16-
if is_no_color {
17-
Self {
18-
reset: "",
19-
blue: "",
20-
cyan: "",
21-
green: "",
22-
yellow: "",
23-
red: "",
24-
magenta: "",
25-
}
26-
} else {
27-
Self {
28-
reset: "\x1b[0m",
29-
blue: "\x1b[34m",
30-
cyan: "\x1b[36m",
31-
green: "\x1b[32m",
32-
yellow: "\x1b[33m",
33-
red: "\x1b[31m",
34-
magenta: "\x1b[35m",
35-
}
36-
}
14+
const fn new(is_no_color: bool) -> Self {
15+
if is_no_color {
16+
Self {
17+
reset: "",
18+
blue: "",
19+
cyan: "",
20+
green: "",
21+
yellow: "",
22+
red: "",
23+
magenta: "",
24+
}
25+
} else {
26+
Self {
27+
reset: "\x1b[0m",
28+
blue: "\x1b[34m",
29+
cyan: "\x1b[36m",
30+
green: "\x1b[32m",
31+
yellow: "\x1b[33m",
32+
red: "\x1b[31m",
33+
magenta: "\x1b[35m",
34+
}
3735
}
36+
}
3837
}
3938

4039
pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
41-
// check for NO_COLOR once at startup
42-
let is_no_color = env::var("NO_COLOR").is_ok();
43-
Colors::new(is_no_color)
40+
// check for NO_COLOR once at startup
41+
let is_no_color = env::var("NO_COLOR").is_ok();
42+
Colors::new(is_no_color)
4443
});
4544

45+
#[must_use]
4646
pub fn print_dots() -> String {
47-
format!(
48-
"{} {} {} {} {} {} {}",
49-
COLORS.blue,
50-
COLORS.cyan,
51-
COLORS.green,
52-
COLORS.yellow,
53-
COLORS.red,
54-
COLORS.magenta,
55-
COLORS.reset,
56-
)
47+
format!(
48+
"{} {} {} {} {} {} {}",
49+
COLORS.blue,
50+
COLORS.cyan,
51+
COLORS.green,
52+
COLORS.yellow,
53+
COLORS.red,
54+
COLORS.magenta,
55+
COLORS.reset,
56+
)
5757
}

src/desktop.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
#[must_use]
12
pub fn get_desktop_info() -> String {
2-
// Retrieve the environment variables and handle Result types
3-
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
4-
let display_backend_result = std::env::var("XDG_SESSION_TYPE");
3+
// Retrieve the environment variables and handle Result types
4+
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
5+
let display_backend_result = std::env::var("XDG_SESSION_TYPE");
56

6-
// Capitalize the first letter of the display backend value
7-
let mut display_backend = display_backend_result.unwrap_or_default();
8-
if let Some(c) = display_backend.as_mut_str().get_mut(0..1) {
9-
c.make_ascii_uppercase();
10-
}
7+
// Capitalize the first letter of the display backend value
8+
let mut display_backend = display_backend_result.unwrap_or_default();
9+
if let Some(c) = display_backend.as_mut_str().get_mut(0..1) {
10+
c.make_ascii_uppercase();
11+
}
1112

12-
// Trim "none+" from the start of desktop_env if present
13-
// Use "Unknown" if desktop_env is empty or has an error
14-
let desktop_env = match desktop_env {
15-
Err(_) => "Unknown".to_string(),
16-
Ok(s) => s.trim_start_matches("none+").to_string(),
17-
};
13+
// Trim "none+" from the start of desktop_env if present
14+
// Use "Unknown" if desktop_env is empty or has an error
15+
let desktop_env = match desktop_env {
16+
Err(_) => "Unknown".to_owned(),
17+
Ok(s) => s.trim_start_matches("none+").to_owned(),
18+
};
1819

19-
// Handle the case where display_backend might be empty after capitalization
20-
let display_backend = if display_backend.is_empty() {
21-
"Unknown"
22-
} else {
23-
&display_backend
24-
}
25-
.to_string();
20+
// Handle the case where display_backend might be empty after capitalization
21+
let display_backend = if display_backend.is_empty() {
22+
"Unknown"
23+
} else {
24+
&display_backend
25+
}
26+
.to_owned();
2627

27-
format!("{desktop_env} ({display_backend})")
28+
format!("{desktop_env} ({display_backend})")
2829
}

src/release.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
use nix::sys::utsname::UtsName;
21
use std::{
3-
fs::File,
4-
io::{self, BufRead, BufReader},
2+
fs::File,
3+
io::{self, BufRead, BufReader},
54
};
65

6+
use nix::sys::utsname::UtsName;
7+
8+
#[must_use]
79
pub fn get_system_info(utsname: &UtsName) -> String {
8-
format!(
9-
"{} {} ({})",
10-
utsname.sysname().to_str().unwrap_or("Unknown"),
11-
utsname.release().to_str().unwrap_or("Unknown"),
12-
utsname.machine().to_str().unwrap_or("Unknown")
13-
)
10+
format!(
11+
"{} {} ({})",
12+
utsname.sysname().to_str().unwrap_or("Unknown"),
13+
utsname.release().to_str().unwrap_or("Unknown"),
14+
utsname.machine().to_str().unwrap_or("Unknown")
15+
)
1416
}
1517

1618
pub fn get_os_pretty_name() -> Result<String, io::Error> {
17-
let file = File::open("/etc/os-release")?;
18-
let reader = BufReader::new(file);
19+
let file = File::open("/etc/os-release")?;
20+
let reader = BufReader::new(file);
1921

20-
for line in reader.lines() {
21-
let line = line?;
22-
if let Some(pretty_name) = line.strip_prefix("PRETTY_NAME=") {
23-
if let Some(trimmed) = pretty_name
24-
.strip_prefix('"')
25-
.and_then(|s| s.strip_suffix('"'))
26-
{
27-
return Ok(trimmed.to_string());
28-
}
29-
return Ok(pretty_name.to_string());
30-
}
22+
for line in reader.lines() {
23+
let line = line?;
24+
if let Some(pretty_name) = line.strip_prefix("PRETTY_NAME=") {
25+
if let Some(trimmed) = pretty_name
26+
.strip_prefix('"')
27+
.and_then(|s| s.strip_suffix('"'))
28+
{
29+
return Ok(trimmed.to_owned());
30+
}
31+
return Ok(pretty_name.to_owned());
3132
}
32-
Ok("Unknown".to_string())
33+
}
34+
Ok("Unknown".to_owned())
3335
}

0 commit comments

Comments
 (0)