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"] }
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 }

View file

@ -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)

View file

@ -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, &regular),
@ -99,6 +99,6 @@ fn pick_maps<R: Rng>(rng: &mut R, pool: &[i32], prev: &[i32], exclude: &[i32]) -
let mut shuffled = source;
shuffled.shuffle(rng);
let mut picked: Vec<i32> = shuffled.into_iter().take(2).collect();
picked.sort();
picked.sort_unstable();
picked
}

View file

@ -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<i32> {
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<i32> = Vec::with_capacity(2);
for p in &parts {
match p.trim().parse::<i32>() {
Ok(n) => ids.push(n),
Err(_) => {
if let Ok(n) = p.trim().parse::<i32>() { 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<String> {
let prefix = format!("{}=", flag_name);
let prefix = format!("{flag_name}=");
if arg.starts_with(&prefix) {
Some(arg[prefix.len()..].to_string())
} else {
@ -94,14 +91,11 @@ fn split_eq_value(arg: &str, flag_name: &str) -> Option<String> {
}
fn require_interval(current: Option<usize>) -> usize {
match current {
Some(n) => n,
None => {
if let Some(n) = current { n } else {
eprintln!("error: --regular/--ranked/--rule must follow an --interval flag");
exit(1);
}
}
}
fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) {
let raw: Vec<String> = std::env::args().collect();
@ -127,16 +121,12 @@ fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) {
}
raw[i].clone()
};
match value.parse::<usize>() {
Ok(n) => current_interval = Some(n),
Err(_) => {
if let Ok(n) = value.parse::<usize>() { current_interval = Some(n) } else {
eprintln!(
"error: --interval value '{}' is not a valid positive integer",
value
"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") {
v
@ -179,8 +169,7 @@ fn parse_overrides() -> (HashMap<usize, RotationOverride>, Vec<String>) {
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")
}