Skip to content

Commit

Permalink
Apply a number of clippy automagic fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Egger <[email protected]>
  • Loading branch information
therealprof committed Sep 6, 2024
1 parent 2a141d8 commit a65cf96
Show file tree
Hide file tree
Showing 21 changed files with 454 additions and 463 deletions.
161 changes: 76 additions & 85 deletions src/main.rs

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions src/usp_builder/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ pub struct CreateObjectBuilder {
}

impl CreateObjectBuilder {
pub const fn new(obj_path: String) -> Self {
#[must_use] pub const fn new(obj_path: String) -> Self {
Self {
obj_path,
param_settings: vec![],
}
}

pub fn with_param_settings(mut self, param_settings: Vec<(String, String, bool)>) -> Self {
#[must_use] pub fn with_param_settings(mut self, param_settings: Vec<(String, String, bool)>) -> Self {
self.param_settings = param_settings;
self
}
Expand Down Expand Up @@ -51,31 +51,31 @@ pub struct AddBuilder {
}

impl AddBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self {
allow_partial: false,
create_objs: vec![],
}
}

pub fn with_allow_partial(mut self, allow_partial: bool) -> Self {
#[must_use] pub const fn with_allow_partial(mut self, allow_partial: bool) -> Self {
self.allow_partial = allow_partial;
self
}

pub fn with_create_objs(mut self, create_objs: Vec<CreateObjectBuilder>) -> Self {
#[must_use] pub fn with_create_objs(mut self, create_objs: Vec<CreateObjectBuilder>) -> Self {
self.create_objs = create_objs;
self
}

pub fn build(self) -> Result<Body<'static>> {
use crate::usp::mod_Body::OneOfmsg_body::*;
use crate::usp::mod_Request::OneOfreq_type::*;
use crate::usp::mod_Body::OneOfmsg_body::request;
use crate::usp::mod_Request::OneOfreq_type::add;

let create_objs = self
.create_objs
.into_iter()
.map(|b| b.build())
.map(CreateObjectBuilder::build)
.collect::<Result<Vec<_>>>()?;

Ok(Body {
Expand Down Expand Up @@ -121,18 +121,18 @@ pub enum AddOperationStatus {
}

impl AddOperationStatus {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self::None
}

pub fn set_failure(self, err_code: u32, err_msg: Option<String>) -> Self {
#[must_use] pub fn set_failure(self, err_code: u32, err_msg: Option<String>) -> Self {
Self::Failure(AddOperationFailureBuilder {
err_code,
err_msg: err_msg.unwrap_or_else(|| usp_errors::get_err_msg(err_code).to_string()),
})
}

pub fn set_success(
#[must_use] pub fn set_success(
self,
instantiated_path: String,
param_errs: Vec<AddRespParameterError>,
Expand All @@ -147,17 +147,17 @@ impl AddOperationStatus {

pub fn build(self) -> Result<OperationStatus<'static>> {
use crate::usp::mod_AddResp::mod_CreatedObjectResult::mod_OperationStatus::{
OneOfoper_status::*, OperationFailure, OperationSuccess,
OneOfoper_status::{oper_failure, oper_success}, OperationFailure, OperationSuccess,
};
use crate::usp::mod_AddResp::ParameterError;
match self {
AddOperationStatus::Failure(f) => Ok(OperationStatus {
Self::Failure(f) => Ok(OperationStatus {
oper_status: oper_failure(OperationFailure {
err_code: f.err_code,
err_msg: f.err_msg.into(),
}),
}),
AddOperationStatus::Success(s) => Ok(OperationStatus {
Self::Success(s) => Ok(OperationStatus {
oper_status: oper_success(OperationSuccess {
instantiated_path: s.instantiated_path.into(),
param_errs: s
Expand All @@ -180,7 +180,7 @@ impl AddOperationStatus {
.collect(),
}),
}),
AddOperationStatus::None => Err(anyhow::anyhow!("")),
Self::None => Err(anyhow::anyhow!("")),
}
}
}
Expand All @@ -192,7 +192,7 @@ pub struct CreatedObjectResultsBuilder {
}

impl CreatedObjectResultsBuilder {
pub const fn new(requested_path: String, oper_status: AddOperationStatus) -> Self {
#[must_use] pub const fn new(requested_path: String, oper_status: AddOperationStatus) -> Self {
Self {
requested_path,
oper_status,
Expand All @@ -213,13 +213,13 @@ pub struct AddRespBuilder {
}

impl AddRespBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self {
created_obj_results: vec![],
}
}

pub fn with_created_obj_results(
#[must_use] pub fn with_created_obj_results(
mut self,
created_obj_results: Vec<CreatedObjectResultsBuilder>,
) -> Self {
Expand All @@ -228,13 +228,13 @@ impl AddRespBuilder {
}

pub fn build(self) -> Result<Body<'static>> {
use crate::usp::mod_Body::OneOfmsg_body::*;
use crate::usp::mod_Response::OneOfresp_type::*;
use crate::usp::mod_Body::OneOfmsg_body::response;
use crate::usp::mod_Response::OneOfresp_type::add_resp;

let created_obj_results = self
.created_obj_results
.into_iter()
.map(|b| b.build())
.map(CreatedObjectResultsBuilder::build)
.collect::<Result<Vec<_>>>()?;

Ok(Body {
Expand Down
20 changes: 10 additions & 10 deletions src/usp_builder/delete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::usp::mod_Body::OneOfmsg_body::{request, response};
use crate::usp::mod_DeleteResp::mod_DeletedObjectResult::mod_OperationStatus::{
OneOfoper_status::*, OperationFailure, OperationSuccess,
OneOfoper_status::{oper_failure, oper_success}, OperationFailure, OperationSuccess,
};
use crate::usp::mod_DeleteResp::UnaffectedPathError;
use crate::usp::mod_DeleteResp::{mod_DeletedObjectResult::OperationStatus, DeletedObjectResult};
Expand All @@ -18,19 +18,19 @@ pub struct DeleteBuilder {
}

impl DeleteBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self {
allow_partial: false,
obj_paths: vec![],
}
}

pub fn with_allow_partial(mut self, allow_partial: bool) -> Self {
#[must_use] pub const fn with_allow_partial(mut self, allow_partial: bool) -> Self {
self.allow_partial = allow_partial;
self
}

pub fn with_obj_paths(mut self, params: Vec<String>) -> Self {
#[must_use] pub fn with_obj_paths(mut self, params: Vec<String>) -> Self {
self.obj_paths = params;
self
}
Expand Down Expand Up @@ -78,22 +78,22 @@ pub struct DeletedObjectResultsBuilder {
}

impl DeletedObjectResultsBuilder {
pub const fn new(requested_path: String) -> Self {
#[must_use] pub const fn new(requested_path: String) -> Self {
Self {
requested_path,
oper_status: DeleteRespOperationStatus::None,
}
}

pub fn set_failure(mut self, err_code: u32, err_msg: Option<String>) -> Self {
#[must_use] pub fn set_failure(mut self, err_code: u32, err_msg: Option<String>) -> Self {
self.oper_status = DeleteRespOperationStatus::Failure {
err_code,
err_msg: err_msg.unwrap_or_else(|| usp_errors::get_err_msg(err_code).to_string()),
};
self
}

pub fn set_success(
#[must_use] pub fn set_success(
mut self,
affected_paths: Vec<String>,
unaffected_path_errs: Vec<DeleteRespUnaffectedPathError>,
Expand Down Expand Up @@ -145,13 +145,13 @@ pub struct DeleteRespBuilder {
}

impl DeleteRespBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self {
deleted_obj_results: vec![],
}
}

pub fn with_deleted_obj_results(
#[must_use] pub fn with_deleted_obj_results(
mut self,
deleted_obj_results: Vec<DeletedObjectResultsBuilder>,
) -> Self {
Expand All @@ -168,7 +168,7 @@ impl DeleteRespBuilder {
deleted_obj_results: self
.deleted_obj_results
.into_iter()
.map(|r| r.build())
.map(DeletedObjectResultsBuilder::build)
.collect::<Result<Vec<_>>>()?,
}
}),
Expand Down
20 changes: 10 additions & 10 deletions src/usp_builder/deregister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub struct DeregisterBuilder {
}

impl DeregisterBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self { paths: vec![] }
}

pub fn with_paths(mut self, paths: Vec<String>) -> Self {
#[must_use] pub fn with_paths(mut self, paths: Vec<String>) -> Self {
self.paths = paths;
self
}
Expand All @@ -33,7 +33,7 @@ impl DeregisterBuilder {
Request {
req_type: deregister({
Deregister {
paths: self.paths.into_iter().map(|p| p.into()).collect(),
paths: self.paths.into_iter().map(std::convert::Into::into).collect(),
}
}),
}
Expand All @@ -56,22 +56,22 @@ pub struct DeregisteredPathResultBuilder {
}

impl DeregisteredPathResultBuilder {
pub const fn new(requested_path: String) -> Self {
#[must_use] pub const fn new(requested_path: String) -> Self {
Self {
requested_path,
oper_status: DeregisterOperationStatus::None,
}
}

pub fn set_failure(mut self, err_code: u32, err_msg: Option<String>) -> Self {
#[must_use] pub fn set_failure(mut self, err_code: u32, err_msg: Option<String>) -> Self {
self.oper_status = DeregisterOperationStatus::Failure {
err_code,
err_msg: err_msg.unwrap_or_else(|| usp_errors::get_err_msg(err_code).to_string()),
};
self
}

pub fn set_success(mut self, deregistered_path: Vec<String>) -> Self {
#[must_use] pub fn set_success(mut self, deregistered_path: Vec<String>) -> Self {
self.oper_status = DeregisterOperationStatus::Success(deregistered_path);
self
}
Expand All @@ -88,7 +88,7 @@ impl DeregisteredPathResultBuilder {
}),
DeregisterOperationStatus::Success(s) => Ok(OperationStatus {
oper_status: OneOfoper_status::oper_success(OperationSuccess {
deregistered_path: s.into_iter().map(|r| r.into()).collect::<Vec<_>>(),
deregistered_path: s.into_iter().map(std::convert::Into::into).collect::<Vec<_>>(),
}),
}),
DeregisterOperationStatus::None => Err(anyhow::anyhow!("")),
Expand All @@ -103,13 +103,13 @@ pub struct DeregisterRespBuilder {
}

impl DeregisterRespBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self {
deregistered_path_results: vec![],
}
}

pub fn with_deregistered_path_results(
#[must_use] pub fn with_deregistered_path_results(
mut self,
deregistered_path_results: Vec<DeregisteredPathResultBuilder>,
) -> Self {
Expand All @@ -121,7 +121,7 @@ impl DeregisterRespBuilder {
let deregistered_path_results = self
.deregistered_path_results
.into_iter()
.map(|r| r.build())
.map(DeregisteredPathResultBuilder::build)
.collect::<Result<Vec<_>>>()?;

Ok(Body {
Expand Down
6 changes: 3 additions & 3 deletions src/usp_builder/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ pub struct ErrorBuilder {
}

impl ErrorBuilder {
pub const fn new() -> Self {
#[must_use] pub const fn new() -> Self {
Self {
code: 0,
message: None,
param_errs: vec![],
}
}

pub fn set_err(mut self, code: u32, message: Option<String>) -> Self {
#[must_use] pub fn set_err(mut self, code: u32, message: Option<String>) -> Self {
self.code = code;
self.message = message;
self
}

pub fn with_param_errs(mut self, errs: Vec<(String, u32, String)>) -> Self {
#[must_use] pub fn with_param_errs(mut self, errs: Vec<(String, u32, String)>) -> Self {
self.param_errs = errs;
self
}
Expand Down
Loading

0 comments on commit a65cf96

Please sign in to comment.