From 4725b45c56751756a3ac982bfe99be112dae6b6d Mon Sep 17 00:00:00 2001 From: Jacob Magnusson Date: Sun, 24 Oct 2021 22:17:51 +0200 Subject: [PATCH] fix: Implement clippy suggestions and format code --- src/cli.rs | 6 +++++- src/lib.rs | 6 +++--- src/params.rs | 15 ++++++++++----- src/requester.rs | 2 +- src/rest_api.rs | 5 ++--- src/suiteql.rs | 13 +++++++++---- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index e7a6404..b08f127 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -47,7 +47,11 @@ pub fn run() -> Result<(), Error> { let api = RestApi::new(&config); match &opts.subcmd { - SubCommand::SuiteQl { query, limit, offset } => { + SubCommand::SuiteQl { + query, + limit, + offset, + } => { let result = api.suiteql.raw(query, *limit, *offset)?; println!("{}", result); } diff --git a/src/lib.rs b/src/lib.rs index aa85e63..cd9a724 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,12 @@ #![doc = include_str!("../README.md")] pub mod cli; mod config; -mod requester; -mod params; -mod suiteql; mod error; pub mod oauth1; +mod params; +mod requester; mod rest_api; +mod suiteql; pub use config::*; pub use error::*; diff --git a/src/params.rs b/src/params.rs index 7251098..77eb07e 100644 --- a/src/params.rs +++ b/src/params.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; - #[derive(Debug, Clone)] pub struct Params<'a>(Vec<(&'a str, &'a str)>); @@ -18,12 +17,18 @@ impl<'a> Params<'a> { } } -impl<'a> Into> for Params<'a> { - fn into(self) -> HashMap<&'a str, &'a str> { - let mut map = HashMap::with_capacity(self.0.len()); - for (k, v) in self.0 { +impl<'a> From> for HashMap<&'a str, &'a str> { + fn from(params: Params<'a>) -> Self { + let mut map = Self::with_capacity(params.0.len()); + for (k, v) in params.0 { map.insert(k, v); } map } } + +impl<'a> Default for Params<'a> { + fn default() -> Self { + Self::new() + } +} diff --git a/src/requester.rs b/src/requester.rs index 25ddb1f..25362bb 100644 --- a/src/requester.rs +++ b/src/requester.rs @@ -1,7 +1,7 @@ use crate::config::Config; use crate::oauth1; -use crate::Error; use crate::params::Params; +use crate::Error; use http::Method; use log::info; diff --git a/src/rest_api.rs b/src/rest_api.rs index 31f3f17..242204d 100644 --- a/src/rest_api.rs +++ b/src/rest_api.rs @@ -1,9 +1,8 @@ use crate::config::Config; -use crate::suiteql::SuiteQl; use crate::requester::Requester; +use crate::suiteql::SuiteQl; -static DEFAULT_BASE_URL: &'static str = - "https://{}.suitetalk.api.netsuite.com/services/rest/query/v1"; +static DEFAULT_BASE_URL: &str = "https://{}.suitetalk.api.netsuite.com/services/rest/query/v1"; pub struct RestApi<'a> { pub suiteql: SuiteQl<'a>, diff --git a/src/suiteql.rs b/src/suiteql.rs index 8ffd854..42cab10 100644 --- a/src/suiteql.rs +++ b/src/suiteql.rs @@ -1,14 +1,19 @@ use crate::error::Error; -use crate::requester::Requester; use crate::params::Params; +use crate::requester::Requester; use http::Method; -pub struct SuiteQl<'a> { requester: Requester<'a>, limit: usize } +pub struct SuiteQl<'a> { + requester: Requester<'a>, + limit: usize, +} impl<'a> SuiteQl<'a> { - pub fn new(requester: Requester<'a>) -> Self { - Self { requester, limit: 1000 } + Self { + requester, + limit: 1000, + } } pub fn set_limit(&mut self, limit: usize) {