diff --git a/Cargo.toml b/Cargo.toml index d2931cd..7fe6a9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,8 @@ chrono = "0.4" clap = { version = "4.6", features = ["derive"] } rand = "0.10" 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 } diff --git a/src/exporter.rs b/src/exporter.rs index e29b092..651db49 100644 --- a/src/exporter.rs +++ b/src/exporter.rs @@ -8,12 +8,12 @@ use roead::byml::Byml; */ fn fix_yaml(byml: &Byml) -> 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::Map(map) => { let mut new_map = roead::byml::Map::default(); new_map.reserve(map.len()); - for (k, v) in map.iter() { + for (k, v) in map { new_map.insert(k.clone(), fix_yaml(v)); } Byml::Map(new_map) diff --git a/src/generator.rs b/src/generator.rs index e8d02c1..f895149 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -40,7 +40,7 @@ pub fn generate( let regular = match override_opt.and_then(|o| o.regular.as_ref()) { Some(maps) => { let mut sorted = maps.clone(); - sorted.sort(); + sorted.sort_unstable(); sorted } 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()) { Some(maps) => { let mut sorted = maps.clone(); - sorted.sort(); + sorted.sort_unstable(); sorted } None => pick_maps(&mut rng, MAP_IDS, &prev_gachi, ®ular), @@ -99,6 +99,6 @@ fn pick_maps(rng: &mut R, pool: &[i32], prev: &[i32], exclude: &[i32]) - let mut shuffled = source; shuffled.shuffle(rng); let mut picked: Vec = shuffled.into_iter().take(2).collect(); - picked.sort(); + picked.sort_unstable(); picked } diff --git a/src/main.rs b/src/main.rs index 81a073e..0873e5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ use generator::RotationOverride; const DEFAULT: usize = 21 * 24 / 2; // If no start time is specified, use the last even hour +#[must_use] pub fn default_timestamp() -> i64 { let now = Utc::now().timestamp(); let block = 2 * 60 * 60; @@ -55,7 +56,7 @@ struct Args { #[arg(long)] yml: bool, - /// Set DisconnectByMemoryHash to true + /// Set `DisconnectByMemoryHash` to true #[arg(long)] hash_kick: bool, } @@ -66,26 +67,22 @@ fn parse_map_ids(raw: &str, flag: &str) -> Vec { let parts: Vec<&str> = raw.split(',').collect(); if parts.len() != 2 { eprintln!( - "error: {} requires exactly 2 comma-separated map IDs, got '{}'", - flag, raw + "error: {flag} requires exactly 2 comma-separated map IDs, got '{raw}'" ); exit(1); } let mut ids: Vec = Vec::with_capacity(2); for p in &parts { - match p.trim().parse::() { - Ok(n) => ids.push(n), - Err(_) => { - eprintln!("error: {} contains invalid map ID '{}'", flag, p.trim()); - exit(1); - } + if let Ok(n) = p.trim().parse::() { ids.push(n) } else { + eprintln!("error: {} contains invalid map ID '{}'", flag, p.trim()); + exit(1); } } ids } fn split_eq_value(arg: &str, flag_name: &str) -> Option { - let prefix = format!("{}=", flag_name); + let prefix = format!("{flag_name}="); if arg.starts_with(&prefix) { Some(arg[prefix.len()..].to_string()) } else { @@ -94,12 +91,9 @@ fn split_eq_value(arg: &str, flag_name: &str) -> Option { } fn require_interval(current: Option) -> usize { - match current { - Some(n) => n, - None => { - eprintln!("error: --regular/--ranked/--rule must follow an --interval flag"); - exit(1); - } + if let Some(n) = current { n } else { + eprintln!("error: --regular/--ranked/--rule must follow an --interval flag"); + exit(1); } } @@ -127,15 +121,11 @@ fn parse_overrides() -> (HashMap, Vec) { } raw[i].clone() }; - match value.parse::() { - Ok(n) => current_interval = Some(n), - Err(_) => { - eprintln!( - "error: --interval value '{}' is not a valid positive integer", - value - ); - exit(1); - } + if let Ok(n) = value.parse::() { current_interval = Some(n) } else { + eprintln!( + "error: --interval value '{value}' is not a valid positive integer" + ); + exit(1); } } else if arg == "--regular" || split_eq_value(arg, "--regular").is_some() { let value = if let Some(v) = split_eq_value(arg, "--regular") { @@ -179,8 +169,7 @@ fn parse_overrides() -> (HashMap, Vec) { let interval = require_interval(current_interval); if !VALID_RULES.contains(&value.as_str()) { eprintln!( - "error: --rule must be one of {:?}, got '{}'", - VALID_RULES, value + "error: --rule must be one of {VALID_RULES:?}, got '{value}'" ); exit(1); } @@ -231,5 +220,5 @@ fn derive_yml_path(output: &str) -> String { } return format!("{}.yml", stem.to_string_lossy()); } - format!("{}.yml", output) + format!("{output}.yml") }