chore: clippy fixes

This commit is contained in:
Jerry Starke 2026-08-10 04:22:01 +02:00
commit 4dc650f675
4 changed files with 27 additions and 33 deletions

View file

@ -8,3 +8,8 @@ chrono = "0.4"
clap = { version = "4.6", features = ["derive"] } clap = { version = "4.6", features = ["derive"] }
rand = "0.10" rand = "0.10"
roead = { version = "1.0", default-features = false, features = ["byml", "yaml"] } roead = { version = "1.0", default-features = false, features = ["byml", "yaml"] }
[lints.clippy]
print_stdout = { level = "deny", priority = 1}
pedantic = { level = "warn", priority = 0 }
all = { level = "warn", priority = -1 }

View file

@ -8,12 +8,12 @@ use roead::byml::Byml;
*/ */
fn fix_yaml(byml: &Byml) -> Byml { fn fix_yaml(byml: &Byml) -> Byml {
match byml { match byml {
Byml::I32(v) => Byml::I64(*v as i64), Byml::I32(v) => Byml::I64(i64::from(*v)),
Byml::Array(arr) => Byml::Array(arr.iter().map(fix_yaml).collect()), Byml::Array(arr) => Byml::Array(arr.iter().map(fix_yaml).collect()),
Byml::Map(map) => { Byml::Map(map) => {
let mut new_map = roead::byml::Map::default(); let mut new_map = roead::byml::Map::default();
new_map.reserve(map.len()); new_map.reserve(map.len());
for (k, v) in map.iter() { for (k, v) in map {
new_map.insert(k.clone(), fix_yaml(v)); new_map.insert(k.clone(), fix_yaml(v));
} }
Byml::Map(new_map) Byml::Map(new_map)

View file

@ -40,7 +40,7 @@ pub fn generate(
let regular = match override_opt.and_then(|o| o.regular.as_ref()) { let regular = match override_opt.and_then(|o| o.regular.as_ref()) {
Some(maps) => { Some(maps) => {
let mut sorted = maps.clone(); let mut sorted = maps.clone();
sorted.sort(); sorted.sort_unstable();
sorted sorted
} }
None => pick_maps(&mut rng, MAP_IDS, &prev_regular, &[]), None => pick_maps(&mut rng, MAP_IDS, &prev_regular, &[]),
@ -49,7 +49,7 @@ pub fn generate(
let gachi = match override_opt.and_then(|o| o.ranked.as_ref()) { let gachi = match override_opt.and_then(|o| o.ranked.as_ref()) {
Some(maps) => { Some(maps) => {
let mut sorted = maps.clone(); let mut sorted = maps.clone();
sorted.sort(); sorted.sort_unstable();
sorted sorted
} }
None => pick_maps(&mut rng, MAP_IDS, &prev_gachi, &regular), None => pick_maps(&mut rng, MAP_IDS, &prev_gachi, &regular),
@ -99,6 +99,6 @@ fn pick_maps<R: Rng>(rng: &mut R, pool: &[i32], prev: &[i32], exclude: &[i32]) -
let mut shuffled = source; let mut shuffled = source;
shuffled.shuffle(rng); shuffled.shuffle(rng);
let mut picked: Vec<i32> = shuffled.into_iter().take(2).collect(); let mut picked: Vec<i32> = shuffled.into_iter().take(2).collect();
picked.sort(); picked.sort_unstable();
picked picked
} }

View file

@ -14,6 +14,7 @@ use generator::RotationOverride;
const DEFAULT: usize = 21 * 24 / 2; const DEFAULT: usize = 21 * 24 / 2;
// If no start time is specified, use the last even hour // If no start time is specified, use the last even hour
#[must_use]
pub fn default_timestamp() -> i64 { pub fn default_timestamp() -> i64 {
let now = Utc::now().timestamp(); let now = Utc::now().timestamp();
let block = 2 * 60 * 60; let block = 2 * 60 * 60;
@ -55,7 +56,7 @@ struct Args {
#[arg(long)] #[arg(long)]
yml: bool, yml: bool,
/// Set DisconnectByMemoryHash to true /// Set `DisconnectByMemoryHash` to true
#[arg(long)] #[arg(long)]
hash_kick: bool, hash_kick: bool,
} }
@ -66,26 +67,22 @@ fn parse_map_ids(raw: &str, flag: &str) -> Vec<i32> {
let parts: Vec<&str> = raw.split(',').collect(); let parts: Vec<&str> = raw.split(',').collect();
if parts.len() != 2 { if parts.len() != 2 {
eprintln!( eprintln!(
"error: {} requires exactly 2 comma-separated map IDs, got '{}'", "error: {flag} requires exactly 2 comma-separated map IDs, got '{raw}'"
flag, raw
); );
exit(1); exit(1);
} }
let mut ids: Vec<i32> = Vec::with_capacity(2); let mut ids: Vec<i32> = Vec::with_capacity(2);
for p in &parts { for p in &parts {
match p.trim().parse::<i32>() { if let Ok(n) = p.trim().parse::<i32>() { ids.push(n) } else {
Ok(n) => ids.push(n),
Err(_) => {
eprintln!("error: {} contains invalid map ID '{}'", flag, p.trim()); eprintln!("error: {} contains invalid map ID '{}'", flag, p.trim());
exit(1); exit(1);
} }
} }
}
ids ids
} }
fn split_eq_value(arg: &str, flag_name: &str) -> Option<String> { fn split_eq_value(arg: &str, flag_name: &str) -> Option<String> {
let prefix = format!("{}=", flag_name); let prefix = format!("{flag_name}=");
if arg.starts_with(&prefix) { if arg.starts_with(&prefix) {
Some(arg[prefix.len()..].to_string()) Some(arg[prefix.len()..].to_string())
} else { } else {
@ -94,13 +91,10 @@ fn split_eq_value(arg: &str, flag_name: &str) -> Option<String> {
} }
fn require_interval(current: Option<usize>) -> usize { fn require_interval(current: Option<usize>) -> usize {
match current { if let Some(n) = current { n } else {
Some(n) => n,
None => {
eprintln!("error: --regular/--ranked/--rule must follow an --interval flag"); eprintln!("error: --regular/--ranked/--rule must follow an --interval flag");
exit(1); exit(1);
} }
}
} }
fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) { fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) {
@ -127,16 +121,12 @@ fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) {
} }
raw[i].clone() raw[i].clone()
}; };
match value.parse::<usize>() { if let Ok(n) = value.parse::<usize>() { current_interval = Some(n) } else {
Ok(n) => current_interval = Some(n),
Err(_) => {
eprintln!( eprintln!(
"error: --interval value '{}' is not a valid positive integer", "error: --interval value '{value}' is not a valid positive integer"
value
); );
exit(1); exit(1);
} }
}
} else if arg == "--regular" || split_eq_value(arg, "--regular").is_some() { } else if arg == "--regular" || split_eq_value(arg, "--regular").is_some() {
let value = if let Some(v) = split_eq_value(arg, "--regular") { let value = if let Some(v) = split_eq_value(arg, "--regular") {
v v
@ -179,8 +169,7 @@ fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) {
let interval = require_interval(current_interval); let interval = require_interval(current_interval);
if !VALID_RULES.contains(&value.as_str()) { if !VALID_RULES.contains(&value.as_str()) {
eprintln!( eprintln!(
"error: --rule must be one of {:?}, got '{}'", "error: --rule must be one of {VALID_RULES:?}, got '{value}'"
VALID_RULES, value
); );
exit(1); exit(1);
} }
@ -231,5 +220,5 @@ fn derive_yml_path(output: &str) -> String {
} }
return format!("{}.yml", stem.to_string_lossy()); return format!("{}.yml", stem.to_string_lossy());
} }
format!("{}.yml", output) format!("{output}.yml")
} }