Files
RedBear-OS/src/cook/ident.rs
T
vasilito 0c541f6161 refactor: auto-fix 100 clippy warnings (needless_borrow, collapsible_if, len_zero, etc.)
cargo clippy --fix reduced warnings from 196 to 96 (51% reduction).

Categories fixed:
- needless_borrow (52): removed redundant & on already-referenced values
- collapsible_if (20): nested ifs → single if with let chains (Rust 2024)
- len_zero (8): x.len() == 0 → x.is_empty()
- redundant_field_names (4): field: field → field
- needless_return (3): removed trailing return
- redundant_closure (2): |x| f(x) → f
- Other mechanical (11): useless_conversion, map_entry, derivable_impls, etc.

Verification: cargo check , cargo test --lib  38/38, cargo clippy 96 remaining
(down from 196). No behavior change — all fixes are semantic equivalents.

Remaining 96 warnings:
- 70 result_large_err (architectural: box Error enum variants)
- 12 ptr_arg (API signature: &PathBuf → &Path)
- 14 other (manual evaluation needed)
2026-07-18 17:48:55 +09:00

47 lines
1.2 KiB
Rust

use std::{
process::{Command, Stdio},
sync::OnceLock,
};
#[derive(Debug, Default)]
pub struct IdentifierConfig {
pub commit: String,
pub time: String,
}
impl IdentifierConfig {
fn new() -> Self {
let (commit, _) = crate::cook::fs::get_git_head_rev(
&std::env::current_dir().expect("unable to get $PWD"),
)
.unwrap_or(("".into(), false));
// better than importing heavy deps like chrono
let time = String::from_utf8_lossy(
Command::new("date")
.arg("-u")
.arg("+%Y-%m-%dT%H:%M:%SZ")
.stdout(Stdio::piped())
.output()
.expect("Failed to get current ISO-formatted time")
.stdout
.trim_ascii(),
)
.into();
IdentifierConfig { commit, time }
}
}
static IDENTIFIER_CONFIG: OnceLock<IdentifierConfig> = OnceLock::new();
pub fn get_ident() -> &'static IdentifierConfig {
IDENTIFIER_CONFIG
.get()
.expect("Identifier is not initialized")
}
pub fn init_ident() {
IDENTIFIER_CONFIG
.set(IdentifierConfig::new())
.expect("Identifier is initialized twice")
}