Skip to content

Commit

Permalink
Clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
DFINITYManu committed Jan 30, 2024
1 parent d444a9e commit d60c77c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ pub struct AddBoundaryNodeToDefinitionBinding {

#[derive(Debug)]

struct DefinitionNotFound(String);
struct DefinitionNotFound {
ic_name: String,
}

impl Error for DefinitionNotFound {}

impl Display for DefinitionNotFound {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
write!(f, "definition {} not found", self)
write!(f, "definition {} not found", self.ic_name)
}
}

Expand All @@ -33,12 +35,13 @@ pub(crate) async fn add_boundary_node(
let log = binding.log.clone();
let name = boundary_node.name.clone();
let ic_name = boundary_node.ic_name.clone();
let rej: String = format!("Definition {} could not be added", name);

let mut definitions = binding.supervisor.definitions.lock().await;
let rej = format!("Definition {} could not be added", name);

let running_definition = match definitions.get_mut(&ic_name) {
Some(d) => d,
None => return not_found(log, rej, DefinitionNotFound(ic_name)),
None => return not_found(log, rej, DefinitionNotFound { ic_name }),
};

let bn = match boundary_node.try_into_boundary_node() {
Expand All @@ -48,6 +51,6 @@ pub(crate) async fn add_boundary_node(

match running_definition.add_boundary_node(bn).await {
Ok(()) => ok(log, format!("Definition {} added successfully", name)),
Err(e) => return bad_request(log, rej, e),
Err(e) => bad_request(log, rej, e),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ pub(crate) async fn add_definition(definition: DefinitionDto, binding: AddDefini
};
match binding.supervisor.start(vec![new_definition], false).await {
Ok(()) => ok(log, format!("Definition {} added successfully", dname)),
Err(e) => return bad_request(log, rej, e.errors.into_iter().next().unwrap()),
Err(e) => bad_request(log, rej, e.errors.into_iter().next().unwrap()),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ pub(crate) async fn replace_definitions(
.collect();
let defsresults: Vec<Result<Definition, BadDtoError>> = join_all(defsresults_futures).await;
let (new_definitions, errors): (Vec<_>, Vec<_>) = defsresults.into_iter().partition(Result::is_ok);
let new_definitions: Vec<_> = new_definitions.into_iter().map(Result::unwrap).collect();
let errors: Vec<_> = errors.into_iter().map(Result::unwrap_err).collect();

let errors: Vec<_> = errors.into_iter().map(Result::unwrap_err).collect();
if !errors.is_empty() {
return bad_request(
log,
Expand All @@ -48,6 +47,7 @@ pub(crate) async fn replace_definitions(
);
}

let new_definitions: Vec<_> = new_definitions.into_iter().map(Result::unwrap).collect();
match binding.supervisor.start(new_definitions, true).await {
Ok(_) => ok(log, format!("Added new definitions {} to existing ones", dnames)),
Err(e) => bad_request(log, rej, format!(":\n{}", e)),
Expand Down

0 comments on commit d60c77c

Please sign in to comment.