From abb69478530407c3e56e18de2b19c7e7d2dfc80c Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Fri, 1 Mar 2019 18:47:47 +0100 Subject: [PATCH] Coding style --- src/command_runner.rs | 12 +++--------- src/factory.rs | 5 +++-- src/loggers.rs | 2 +- src/repository.rs | 2 +- src/schema.rs | 18 +++++++++--------- src/storage.rs | 2 +- src/symbols/acme/account_key.rs | 5 +---- src/symbols/acme/cert.rs | 5 +---- src/symbols/acme/chain.rs | 5 +---- src/symbols/dir.rs | 2 +- src/symbols/factory.rs | 9 ++------- src/symbols/file.rs | 5 +---- src/symbols/git/checkout.rs | 7 +------ src/symbols/git/submodules.rs | 7 ++----- src/symbols/hook.rs | 4 ++-- src/symbols/list.rs | 12 ++++++------ src/symbols/mariadb/database.rs | 6 +----- src/symbols/mariadb/database_dump.rs | 6 +----- src/symbols/mariadb/user.rs | 5 +---- src/symbols/mod.rs | 4 ++-- src/symbols/nginx/server.rs | 8 ++++---- src/symbols/npm.rs | 5 +---- src/symbols/owner.rs | 2 +- src/symbols/stored_directory.rs | 7 +------ src/symbols/systemd/node_js_user_service.rs | 20 ++++++++++---------- src/symbols/systemd/reload.rs | 5 +---- src/symbols/systemd/user_session.rs | 11 ++++------- src/symbols/tls/csr.rs | 5 +---- src/symbols/tls/key.rs | 5 +---- src/symbols/tls/self_signed_cert.rs | 5 +---- src/symbols/user.rs | 18 +++++++----------- src/symbols/wordpress/plugin.rs | 6 +----- src/symbols/wordpress/translation.rs | 10 +++++----- 33 files changed, 79 insertions(+), 151 deletions(-) diff --git a/src/command_runner.rs b/src/command_runner.rs index af5a62a..30ca60f 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -51,10 +51,7 @@ pub struct SetuidCommandRunner<'a, C> where C: 'a + CommandRunner { impl<'a, C> SetuidCommandRunner<'a, C> where C: 'a + CommandRunner { pub fn new(user_name: &'a str, command_runner: &'a C) -> SetuidCommandRunner<'a, C> { - SetuidCommandRunner { - command_runner: command_runner, - user_name: user_name - } + SetuidCommandRunner { command_runner, user_name } } } @@ -68,7 +65,7 @@ impl<'a> TempSetEnv<'a> { fn new(name: &'a str, new_value: String) -> TempSetEnv<'a> { let old_value = env::var(name); env::set_var(name, new_value); - TempSetEnv { name: name, old_value: old_value.ok() } + TempSetEnv { name, old_value: old_value.ok() } } } @@ -101,10 +98,7 @@ pub struct SuCommandRunner<'a, C> where C: 'a + CommandRunner { impl<'a, C> SuCommandRunner<'a, C> where C: 'a + CommandRunner { pub fn new(user_name: &'a str, command_runner: &'a C) -> SuCommandRunner<'a, C> { - SuCommandRunner { - command_runner: command_runner, - user_name: user_name - } + SuCommandRunner { command_runner, user_name } } } diff --git a/src/factory.rs b/src/factory.rs index 5098837..99452db 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -14,12 +14,13 @@ use symbols::tls::{TlsCsr, TlsKey}; use symbols::user::{User, UserAdder}; use symbols::user::SystemUserAdder; +#[derive(Default)] pub struct Factory { } impl Factory { pub fn new() -> Self { - Self {} + Default::default() } pub fn get_repo<'a, CR: CommandRunner>(&self, command_runner: &'a CR) -> DefaultSymbolRepository<'a, SystemUserAdder<'a, CR>, CR> { @@ -47,7 +48,7 @@ pub struct DefaultSymbolRepository<'a, A: 'a + UserAdder, C: 'a + CommandRunner> impl<'a, C: 'a + CommandRunner> DefaultSymbolRepository<'a, SystemUserAdder<'a, C>, C> { pub fn new(command_runner: &'a C) -> Self { Self { - command_runner: command_runner, + command_runner, user_adder: SystemUserAdder::new(command_runner), home: Regex::new("^/home/([^/]+)$").unwrap(), home_config: Regex::new("^/home/([^/]+)/.config(?:/|$)").unwrap(), diff --git a/src/loggers.rs b/src/loggers.rs index 4084e23..33eeb87 100644 --- a/src/loggers.rs +++ b/src/loggers.rs @@ -23,7 +23,7 @@ pub struct FilteringLogger<'a> { impl<'a> FilteringLogger<'a> { pub fn new(logger: &'a mut Logger) -> Self { - FilteringLogger { logger: logger } + FilteringLogger { logger } } } diff --git a/src/repository.rs b/src/repository.rs index 571e622..4429f89 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -19,7 +19,7 @@ pub struct DispatchingSymbolRepository<'a> { impl<'a> DispatchingSymbolRepository<'a> { pub fn new(repositories: HashMap<&'a str, Box + 'a>>) -> Self { - DispatchingSymbolRepository { repositories: repositories } + DispatchingSymbolRepository { repositories } } } diff --git a/src/schema.rs b/src/schema.rs index 6c481a7..7cc8619 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -15,14 +15,14 @@ pub enum SymbolRunError { impl Error for SymbolRunError { fn description(&self) -> &str { match self { - &SymbolRunError::Symbol(_) => "Symbol execution error", - &SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol" + SymbolRunError::Symbol(_) => "Symbol execution error", + SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol" } } fn cause(&self) -> Option<&Error> { match self { - &SymbolRunError::Symbol(ref e) => Some(&**e), - &SymbolRunError::ExecuteDidNotReach(_) => None + SymbolRunError::Symbol(ref e) => Some(&**e), + SymbolRunError::ExecuteDidNotReach(_) => None } } } @@ -30,8 +30,8 @@ impl Error for SymbolRunError { impl fmt::Display for SymbolRunError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - &SymbolRunError::Symbol(ref e) => write!(f, "{}", e), - &SymbolRunError::ExecuteDidNotReach(_) => write!(f, "{}", self.description()) + SymbolRunError::Symbol(ref e) => write!(f, "{}", e), + SymbolRunError::ExecuteDidNotReach(_) => write!(f, "{}", self.description()) } } } @@ -104,11 +104,11 @@ impl<'a, R, L> SymbolRunner for ReportingSymbolRunner<'a, R, L> where R: SymbolR let mut logger = self.1.borrow_mut(); logger.debug(format!("Running symbol {}", symbol).as_str()); let res = self.0.run_symbol(symbol); - match &res { - &Err(ref e) => { + match res { + Err(ref e) => { logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str()); }, - &Ok(_) => { + Ok(_) => { logger.debug(format!("Successfully finished {}", symbol).as_str()); } } diff --git a/src/storage.rs b/src/storage.rs index f102d8a..18fa6c2 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -39,6 +39,6 @@ impl Storage for SimpleStorage { try!(read_dir(dir)) .map(|entry| entry.ok().and_then(|e| e.file_name().into_string().ok()).and_then(|filename| u64::from_str(&filename).ok())) .fold(None, |maybe_newest, maybe_time| maybe_newest.into_iter().chain(maybe_time).max()) - .ok_or("Not found".to_string().into()) + .ok_or_else(|| "Not found".to_string().into()) } } diff --git a/src/symbols/acme/account_key.rs b/src/symbols/acme/account_key.rs index 32f3fb5..5eda75e 100644 --- a/src/symbols/acme/account_key.rs +++ b/src/symbols/acme/account_key.rs @@ -14,10 +14,7 @@ pub struct AcmeAccountKey<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> AcmeAccountKey<'a, C> { pub fn new(path: Cow<'a, Path>, command_runner: &'a C) -> Self { - AcmeAccountKey { - path: path, - command_runner: command_runner - } + AcmeAccountKey { path, command_runner } } fn get_bytes(&self) -> u32 { diff --git a/src/symbols/acme/cert.rs b/src/symbols/acme/cert.rs index 9773f64..a01eae5 100644 --- a/src/symbols/acme/cert.rs +++ b/src/symbols/acme/cert.rs @@ -16,10 +16,7 @@ pub struct AcmeCert<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> AcmeCert<'a, C> { pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self { - AcmeCert { - domain: domain, - command_runner: command_runner - } + AcmeCert { domain, command_runner } } fn get_csr_path(&self) -> String { diff --git a/src/symbols/acme/chain.rs b/src/symbols/acme/chain.rs index 2b82962..5f4c3d9 100644 --- a/src/symbols/acme/chain.rs +++ b/src/symbols/acme/chain.rs @@ -16,10 +16,7 @@ pub struct AcmeCertChain<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> AcmeCertChain<'a, C> { pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self { - AcmeCertChain { - domain: domain, - command_runner: command_runner - } + AcmeCertChain { domain, command_runner } } fn get_single_cert_path(&self) -> String { diff --git a/src/symbols/dir.rs b/src/symbols/dir.rs index a1104e0..8d17693 100644 --- a/src/symbols/dir.rs +++ b/src/symbols/dir.rs @@ -13,7 +13,7 @@ pub struct Dir where D: AsRef { impl Dir where D: AsRef { pub fn new(path: D) -> Self { - Dir { path: path } + Dir { path } } } diff --git a/src/symbols/factory.rs b/src/symbols/factory.rs index b125391..59b793f 100644 --- a/src/symbols/factory.rs +++ b/src/symbols/factory.rs @@ -25,7 +25,7 @@ pub struct DefaultPolicy; impl Policy for DefaultPolicy { fn user_name_for_host(&self, host_name: &'static str) -> String { - host_name.split('.').rev().fold(String::new(), |result, part| if result.len() > 0 { result + "_" } else { result } + part) + host_name.split('.').rev().fold(String::new(), |result, part| if result.is_empty() { result } else { result + "_" } + part) } } @@ -41,12 +41,7 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact let acme_user = "acme"; // FIXME: CONFIG let acme_command_runner = SetuidCommandRunner::new(acme_user, command_runner); - SymbolFactory { - command_runner: command_runner, - acme_command_runner: acme_command_runner, - symbol_runner: symbol_runner, - policy: policy - } + SymbolFactory { command_runner, acme_command_runner, symbol_runner, policy } } pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box { diff --git a/src/symbols/file.rs b/src/symbols/file.rs index 7f443e3..7639a9e 100644 --- a/src/symbols/file.rs +++ b/src/symbols/file.rs @@ -16,10 +16,7 @@ pub struct File where C: Deref, D: AsRef { impl File where C: Deref, D: AsRef { pub fn new(path: D, content: C) -> Self { - File { - path: path, - content: content - } + File { path, content } } } diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index e9c54f2..503c352 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -16,12 +16,7 @@ pub struct GitCheckout<'a, C: 'a + CommandRunner, T: AsRef> { impl<'a, C: CommandRunner, T: AsRef> GitCheckout<'a, C, T> { pub fn new(target: T, source: &'a str, branch: &'a str, command_runner: &'a C) -> Self { - GitCheckout { - target: target, - source: source, - branch: branch, - command_runner: command_runner - } + GitCheckout { target, source, branch, command_runner } } } diff --git a/src/symbols/git/submodules.rs b/src/symbols/git/submodules.rs index 6c40e27..8b4bbe1 100644 --- a/src/symbols/git/submodules.rs +++ b/src/symbols/git/submodules.rs @@ -12,10 +12,7 @@ pub struct GitSubmodules<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> GitSubmodules<'a, C> { pub fn new(target: &'a str, command_runner: &'a C) -> Self { - GitSubmodules { - target: target, - command_runner: command_runner - } + GitSubmodules { target, command_runner } } } @@ -39,7 +36,7 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> { return Ok(false); } let output = try!(String::from_utf8(try!(self._run_in_target_repo(&["submodule", "status"])))); - Ok(output.lines().all(|line| line.len() == 0 || line.starts_with(' '))) + Ok(output.lines().all(|line| line.is_empty() || line.starts_with(' '))) } fn execute(&self) -> Result<(), Box> { diff --git a/src/symbols/hook.rs b/src/symbols/hook.rs index 149f522..bd0b17a 100644 --- a/src/symbols/hook.rs +++ b/src/symbols/hook.rs @@ -12,7 +12,7 @@ pub struct Hook where A: Symbol, B: Symbol { // A and B are executed if either A or B are not reached impl Hook where A: Symbol, B: Symbol { pub fn new(a: A, b: B) -> Self { - Hook { a: a, b: b } + Hook { a, b } } } @@ -41,7 +41,7 @@ impl Symbol for Hook where A: Symbol, B: Symbol { if let Some(provides) = self.b.provides() { r.extend(provides.into_iter()); } - if r.len() > 0 { Some(r) } else { None } + if r.is_empty() { None } else { Some(r) } } fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { diff --git a/src/symbols/list.rs b/src/symbols/list.rs index 02c3a3b..c079a6b 100644 --- a/src/symbols/list.rs +++ b/src/symbols/list.rs @@ -10,7 +10,7 @@ pub struct List<'a> { impl<'a> List<'a> { pub fn new(symbols: Vec>) -> Self { - List { symbols: symbols } + List { symbols } } } @@ -48,7 +48,7 @@ impl<'a> Symbol for List<'a> { r.extend(provides.into_iter()); } } - if r.len() > 0 { Some(r) } else { None } + if r.is_empty() { None } else { Some(r) } } fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { @@ -62,12 +62,12 @@ impl<'a> Symbol for List<'a> { struct SymbolListAction<'a> { runner: &'a SymbolRunner, - symbols: &'a Vec> + symbols: &'a [Box] } impl<'a> SymbolListAction<'a> { - fn new(runner: &'a SymbolRunner, symbols: &'a Vec>) -> Self { - Self { runner: runner, symbols: symbols } + fn new(runner: &'a SymbolRunner, symbols: &'a [Box]) -> Self { + Self { runner, symbols } } } @@ -86,7 +86,7 @@ pub struct ListAction<'a> { impl<'a> ListAction<'a> { pub fn new(actions: Vec>) -> Self { - Self { actions: actions } + Self { actions } } } diff --git a/src/symbols/mariadb/database.rs b/src/symbols/mariadb/database.rs index c2e8017..744c898 100644 --- a/src/symbols/mariadb/database.rs +++ b/src/symbols/mariadb/database.rs @@ -13,11 +13,7 @@ pub struct MariaDBDatabase<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> { pub fn new(db_name: Cow<'a, str>, seed_file: Cow<'a, str>, command_runner: &'a C) -> Self { - MariaDBDatabase { - db_name: db_name, - seed_file: seed_file, - command_runner: command_runner - } + MariaDBDatabase { db_name, seed_file, command_runner } } fn run_sql(&self, sql: &str) -> Result> { diff --git a/src/symbols/mariadb/database_dump.rs b/src/symbols/mariadb/database_dump.rs index 02cc114..9098f6d 100644 --- a/src/symbols/mariadb/database_dump.rs +++ b/src/symbols/mariadb/database_dump.rs @@ -14,11 +14,7 @@ pub struct DatabaseDump<'a, N, C, S> where N: 'a + AsRef, C: 'a + CommandRu impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> { pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self { - DatabaseDump { - db_name: db_name, - storage: storage, - command_runner: command_runner - } + DatabaseDump { db_name, storage, command_runner } } fn run_sql(&self, sql: &str) -> Result> { diff --git a/src/symbols/mariadb/user.rs b/src/symbols/mariadb/user.rs index 7bb980a..803f391 100644 --- a/src/symbols/mariadb/user.rs +++ b/src/symbols/mariadb/user.rs @@ -13,10 +13,7 @@ pub struct MariaDBUser<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> MariaDBUser<'a, C> { pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self { - MariaDBUser { - user_name: user_name, - command_runner: command_runner - } + MariaDBUser { user_name, command_runner } } fn run_sql(&self, sql: &str) -> Result> { diff --git a/src/symbols/mod.rs b/src/symbols/mod.rs index de16eaf..875b389 100644 --- a/src/symbols/mod.rs +++ b/src/symbols/mod.rs @@ -38,7 +38,7 @@ pub struct SymbolAction<'a, S: Symbol + 'a> { impl<'a, S: Symbol> SymbolAction<'a, S> { pub fn new(runner: &'a SymbolRunner, symbol: &'a S) -> Self { - Self { runner: runner, symbol: symbol } + Self { runner, symbol } } } @@ -55,7 +55,7 @@ pub struct OwnedSymbolAction<'a, S: Symbol + 'a> { impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> { pub fn new(runner: &'a SymbolRunner, symbol: S) -> Self { - Self { runner: runner, symbol: symbol } + Self { runner, symbol } } } diff --git a/src/symbols/nginx/server.rs b/src/symbols/nginx/server.rs index ed2407a..135da49 100644 --- a/src/symbols/nginx/server.rs +++ b/src/symbols/nginx/server.rs @@ -23,13 +23,13 @@ impl From for NginxServerError { impl Error for NginxServerError { fn description(&self) -> &str { match self { - &NginxServerError::ExecError(ref e) => e.description(), - &NginxServerError::GenericError => "Generic error" + NginxServerError::ExecError(ref e) => e.description(), + NginxServerError::GenericError => "Generic error" } } fn cause(&self) -> Option<&Error> { match self { - &NginxServerError::ExecError(ref e) => Some(e), + NginxServerError::ExecError(ref e) => Some(e), _ => None } } @@ -123,7 +123,7 @@ location @proxy {{ pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self { let file_path = String::from("/etc/nginx/sites-enabled/") + domain; NginxServer { - command_runner: command_runner, + command_runner, file: FileSymbol::new(file_path, content) } } diff --git a/src/symbols/npm.rs b/src/symbols/npm.rs index 5b13dc7..f54dc3b 100644 --- a/src/symbols/npm.rs +++ b/src/symbols/npm.rs @@ -12,10 +12,7 @@ pub struct NpmInstall<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> NpmInstall<'a, C> { pub fn new(target: &'a str, command_runner: &'a C) -> Self { - NpmInstall { - target: target, - command_runner: command_runner - } + NpmInstall { target, command_runner } } } diff --git a/src/symbols/owner.rs b/src/symbols/owner.rs index 8b8a883..f1ea0c5 100644 --- a/src/symbols/owner.rs +++ b/src/symbols/owner.rs @@ -19,7 +19,7 @@ pub struct Owner<'a, C: 'a + CommandRunner, D> where D: AsRef { impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef { pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a C) -> Self { - Owner { path: path, user_name: user_name, command_runner: command_runner } + Owner { path, user_name, command_runner } } } diff --git a/src/symbols/stored_directory.rs b/src/symbols/stored_directory.rs index 782f4c4..121cc3b 100644 --- a/src/symbols/stored_directory.rs +++ b/src/symbols/stored_directory.rs @@ -23,12 +23,7 @@ pub struct StoredDirectory<'a, S, C: 'a + CommandRunner> where S: Storage { impl<'a, S, C: CommandRunner> StoredDirectory<'a, S, C> where S: Storage { pub fn new(path: Cow<'a, str>, storage: S, dir: StorageDirection, command_runner: &'a C) -> Self { - StoredDirectory { - path: path, - storage: storage, - dir: dir, - command_runner: command_runner - } + StoredDirectory { path, storage, dir, command_runner } } } diff --git a/src/symbols/systemd/node_js_user_service.rs b/src/symbols/systemd/node_js_user_service.rs index e25bf00..e7ecff3 100644 --- a/src/symbols/systemd/node_js_user_service.rs +++ b/src/symbols/systemd/node_js_user_service.rs @@ -28,14 +28,14 @@ impl From for NodeJsSystemdUserServiceError { impl Error for NodeJsSystemdUserServiceError { fn description(&self) -> &str { match self { - &NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(), - &NodeJsSystemdUserServiceError::GenericError => "Generic error", - &NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed" + NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(), + NodeJsSystemdUserServiceError::GenericError => "Generic error", + NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed" } } fn cause(&self) -> Option<&Error> { match self { - &NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e), + NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e), _ => None } } @@ -44,7 +44,7 @@ impl Error for NodeJsSystemdUserServiceError { impl fmt::Display for NodeJsSystemdUserServiceError { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { try!(write!(f, "{}", self.description())); - if let &NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self { + if let NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self { try!(write!(f, ": {:?}", log)); }; Ok(()) @@ -59,10 +59,10 @@ pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref, R: Com } impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner { - pub fn new(home: &'a str, user_name: &'a str, name: &'a str, path: &'a str, command_runner: &'a R) -> Self { - let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), name); + pub fn new(home: &'a str, user_name: &'a str, service_name: &'a str, path: &'a str, command_runner: &'a R) -> Self { + let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), service_name); - let port = format!("/var/tmp/{}-{}.socket", user_name, name); + let port = format!("/var/tmp/{}-{}.socket", user_name, service_name); let content = format!("[Service] Environment=NODE_ENV=production Environment=PORT={1} @@ -81,8 +81,8 @@ WantedBy=default.target ", path, port); NodeJsSystemdUserService { - service_name: name, - user_name: user_name, + service_name, + user_name, command_runner: SetuidCommandRunner::new(user_name, command_runner), file: FileSymbol::new(file_path, content) } diff --git a/src/symbols/systemd/reload.rs b/src/symbols/systemd/reload.rs index ab197f0..7ea5e29 100644 --- a/src/symbols/systemd/reload.rs +++ b/src/symbols/systemd/reload.rs @@ -11,10 +11,7 @@ pub struct ReloadService<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> ReloadService<'a, C> { pub fn new(service: &'a str, command_runner: &'a C) -> Self { - ReloadService { - service: service, - command_runner: command_runner - } + ReloadService { service, command_runner } } } diff --git a/src/symbols/systemd/user_session.rs b/src/symbols/systemd/user_session.rs index 43e5dac..fced756 100644 --- a/src/symbols/systemd/user_session.rs +++ b/src/symbols/systemd/user_session.rs @@ -15,13 +15,13 @@ pub enum SystemdUserSessionError { impl Error for SystemdUserSessionError { fn description(&self) -> &str { match self { - &SystemdUserSessionError::ExecError(ref e) => e.description(), - &SystemdUserSessionError::GenericError => "Generic error" + SystemdUserSessionError::ExecError(ref e) => e.description(), + SystemdUserSessionError::GenericError => "Generic error" } } fn cause(&self) -> Option<&Error> { match self { - &SystemdUserSessionError::ExecError(ref e) => Some(e), + SystemdUserSessionError::ExecError(ref e) => Some(e), _ => None } } @@ -40,10 +40,7 @@ pub struct SystemdUserSession<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> SystemdUserSession<'a, C> { pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self { - SystemdUserSession { - user_name: user_name, - command_runner: command_runner - } + SystemdUserSession { user_name, command_runner } } } diff --git a/src/symbols/tls/csr.rs b/src/symbols/tls/csr.rs index 47d56c7..0fcd700 100644 --- a/src/symbols/tls/csr.rs +++ b/src/symbols/tls/csr.rs @@ -14,10 +14,7 @@ pub struct TlsCsr<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> TlsCsr<'a, C> { pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self { - TlsCsr { - domain: domain, - command_runner: command_runner - } + TlsCsr { domain, command_runner } } fn get_key_path(&self) -> String { diff --git a/src/symbols/tls/key.rs b/src/symbols/tls/key.rs index d936d5c..4166d28 100644 --- a/src/symbols/tls/key.rs +++ b/src/symbols/tls/key.rs @@ -13,10 +13,7 @@ pub struct TlsKey<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> TlsKey<'a, C> { pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self { - TlsKey { - domain: domain, - command_runner: command_runner - } + TlsKey { domain, command_runner } } fn get_path(&self) -> String { diff --git a/src/symbols/tls/self_signed_cert.rs b/src/symbols/tls/self_signed_cert.rs index aaf9369..f35a9d3 100644 --- a/src/symbols/tls/self_signed_cert.rs +++ b/src/symbols/tls/self_signed_cert.rs @@ -14,10 +14,7 @@ pub struct SelfSignedTlsCert<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> SelfSignedTlsCert<'a, C> { pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self { - SelfSignedTlsCert { - domain: domain, - command_runner: command_runner - } + SelfSignedTlsCert { domain, command_runner } } fn get_key_path(&self) -> String { diff --git a/src/symbols/user.rs b/src/symbols/user.rs index 032857f..ca26142 100644 --- a/src/symbols/user.rs +++ b/src/symbols/user.rs @@ -16,14 +16,14 @@ pub enum UserAdderError { impl Error for UserAdderError { fn description(&self) -> &str { match self { - &UserAdderError::AlreadyExists => "User already exists", - &UserAdderError::UnknownError => "Unknown error", - &UserAdderError::ImplError(_) => "User adding error" + UserAdderError::AlreadyExists => "User already exists", + UserAdderError::UnknownError => "Unknown error", + UserAdderError::ImplError(_) => "User adding error" } } fn cause(&self) -> Option<&Error> { match self { - &UserAdderError::ImplError(ref e) => Some(e.as_ref()), + UserAdderError::ImplError(ref e) => Some(e.as_ref()), _ => None } } @@ -50,7 +50,7 @@ pub enum UserError { impl Error for UserError { fn description(&self) -> &str { match self { - &UserError::GenericError => "Could not find out if user exists" + UserError::GenericError => "Could not find out if user exists" } } fn cause(&self) -> Option<&Error> { @@ -77,11 +77,7 @@ pub struct User<'a, C: 'a + CommandRunner, A: 'a + UserAdder> { impl<'a, C: CommandRunner, A: 'a + UserAdder> User<'a, C, A> { pub fn new(user_name: Cow<'a, str>, command_runner: &'a C, user_adder: &'a A) -> Self { - User { - user_name: user_name, - command_runner: command_runner, - user_adder: user_adder - } + User { user_name, command_runner, user_adder } } } @@ -124,7 +120,7 @@ pub struct SystemUserAdder<'a, C: 'a + CommandRunner> { impl<'a, C: CommandRunner> SystemUserAdder<'a, C> { pub fn new(command_runner: &'a C) -> Self { - SystemUserAdder { command_runner: command_runner } + SystemUserAdder { command_runner } } } diff --git a/src/symbols/wordpress/plugin.rs b/src/symbols/wordpress/plugin.rs index e41f24b..f71b5ea 100644 --- a/src/symbols/wordpress/plugin.rs +++ b/src/symbols/wordpress/plugin.rs @@ -19,11 +19,7 @@ pub struct WordpressPlugin<'a, C, R> where C: Deref, R: 'a + Command impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref, R: CommandRunner { pub fn new(base: C, name: C, command_runner: &'a R) -> Self { - WordpressPlugin { - base: base, - name: name, - command_runner: command_runner - } + WordpressPlugin { base, name, command_runner } } fn get_path(&self) -> PathBuf { diff --git a/src/symbols/wordpress/translation.rs b/src/symbols/wordpress/translation.rs index f4c6e29..5ca2283 100644 --- a/src/symbols/wordpress/translation.rs +++ b/src/symbols/wordpress/translation.rs @@ -22,9 +22,9 @@ impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef, R: Co pub fn new>(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self { WordpressTranslation { path: Path::new(path.as_ref()).join("wp-content/languages").to_string_lossy().to_string(), - version: version, - locale: locale, - command_runner: command_runner + version, + locale, + command_runner } } } @@ -35,8 +35,8 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef, D: AsRe let locale: &str = self.locale.as_ref(); let path_locale = if locale == "de_DE" { "de".to_owned() } else { locale.to_lowercase().replace('_', "-") }; let mut res = vec![]; - for &(in_slug, out_slug) in [("", ""), ("cc/", "continents-cities-"), ("admin/", "admin-"), ("admin/network/", "admin-network-")].into_iter() { - for format in ["po", "mo"].into_iter() { + for &(in_slug, out_slug) in [("", ""), ("cc/", "continents-cities-"), ("admin/", "admin-"), ("admin/network/", "admin-network-")].iter() { + for format in ["po", "mo"].iter() { res.push(( format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format), format!("{}/{}{}.{}", self.path.as_ref(), out_slug, self.locale.as_ref(), format)