Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc committed Sep 1, 2024
1 parent 7d771f2 commit 62f2fc1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 40 deletions.
17 changes: 5 additions & 12 deletions maa-cli/src/config/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,32 @@ impl Task {
pub fn new(task_type: TaskType, params: MAAValue) -> Self {
Self {
name: None,
task_type: task_type.into(),
task_type,
strategy: Strategy::default(),
params,
variants: Vec::new(),
}
}

#[cfg(test)]
pub fn with_name(mut self, name: String) -> Self {
self.name = Some(name);
self
}

pub fn with_params(mut self, params: MAAValue) -> Self {
self.params = params;
self
}

#[cfg(test)]
pub fn with_strategy(mut self, strategy: Strategy) -> Self {
self.strategy = strategy;
self
}

#[cfg(test)]
pub fn with_variants(mut self, variants: Vec<TaskVariant>) -> Self {
self.variants = variants;
self
}

#[cfg(test)]
pub fn push_variant(&mut self, variants: TaskVariant) -> &mut Self {
self.variants.push(variants);
self
Expand Down Expand Up @@ -345,12 +344,6 @@ mod tests {

use crate::object;

impl TaskConfig {
pub fn tasks(&self) -> &[Task] {
&self.tasks
}
}

mod task {
use super::*;

Expand Down
12 changes: 5 additions & 7 deletions maa-cli/src/run/preset/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl super::IntoTaskConfig for CopilotParams {

let mut copilot_files = Vec::new();
for uri in &self.uri_list {
let copilot_file = CopilotFile::from_uri(&uri)?;
let copilot_file = CopilotFile::from_uri(uri)?;

copilot_file.push_path_to(&mut copilot_files, copilot_dir)?;
}
Expand Down Expand Up @@ -217,12 +217,10 @@ impl<'a> CopilotFile<'a> {
n if n > 20000 => Ok(CopilotFile::RemoteSet(n)),
n => bail!("Invalid code {n}"),
}
} else if let Some(code) = trimmed.strip_prefix("file://") {
Ok(CopilotFile::Local(Path::new(code)))
} else {
if let Some(code) = trimmed.strip_prefix("file://") {
Ok(CopilotFile::Local(Path::new(code)))
} else {
Ok(CopilotFile::Local(Path::new(trimmed)))
}
Ok(CopilotFile::Local(Path::new(trimmed)))
}
}

Expand Down Expand Up @@ -624,7 +622,7 @@ mod tests {
let ids = [40051, 40052, 40053, 40055, 40056, 40057, 40058, 40059];

ids.iter()
.map(|id| test_root.join(format!("{}.json", id)).into())
.map(|id| test_root.join(format!("{}.json", id)))
.collect::<Vec<PathBuf>>()
}
);
Expand Down
2 changes: 1 addition & 1 deletion maa-cli/src/run/preset/fight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TryFrom<FightParams> for MAAValue {

params.insert("DrGrandet", args.dr_grandet);

return Ok(params);
Ok(params)
}
}

Expand Down
8 changes: 4 additions & 4 deletions maa-cli/src/run/preset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl From<StartUpParams> for MAAValue {

value.maybe_insert("account_name", args.account_name);

return value;
value
}
}

Expand All @@ -84,7 +84,7 @@ impl From<CloseDownParams> for MAAValue {
fn from(args: CloseDownParams) -> Self {
let mut value = MAAValue::new();
value.insert("client_type", args.client.to_str());
return value;
value
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ mod tests {
{
let command = parse_from(args).command;
match command {
Command::StartUp { params, .. } => params.try_into().unwrap(),
Command::StartUp { params, .. } => params.into(),
_ => panic!("Not a StartUp command"),
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ mod tests {
{
let cmd = parse_from(args).command;
match cmd {
Command::CloseDown { params, .. } => params.try_into().unwrap(),
Command::CloseDown { params, .. } => params.into(),
_ => panic!("Not a CloseDown command"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion maa-cli/src/run/preset/reclamation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl From<ReclamationParams> for MAAValue {
value.insert("theme", params.theme.to_str());
value.insert("mode", params.mode);
value.maybe_insert("tool_to_craft", params.tool_to_craft);
return value;
value
}
}

Expand Down
2 changes: 1 addition & 1 deletion maa-cli/src/run/preset/roguelike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl TryFrom<RoguelikeParams> for MAAValue {
_ => {}
}

return Ok(value);
Ok(value)
}
}

Expand Down
14 changes: 0 additions & 14 deletions maa-cli/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,6 @@ impl MAAValue {
}
}

/// Set the given key to true if the value is true
pub fn insert_true(&mut self, key: impl Into<String>, value: bool) {
if value {
self.insert(key, value);
}
}

/// Set the given key to false if the value is false
pub fn insert_false(&mut self, key: impl Into<String>, value: bool) {
if !value {
self.insert(key, value);
}
}

pub fn maybe_insert(&mut self, key: impl Into<String>, value: Option<impl Into<Self>>) {
if let Some(value) = value {
self.insert(key, value);
Expand Down

0 comments on commit 62f2fc1

Please sign in to comment.