From 54458709f945408dafee2d3c72fc65052c580c44 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 24 Sep 2019 17:10:52 +0200 Subject: [PATCH] Simplify DefaultPolicy --- src/symbols/factory.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/symbols/factory.rs b/src/symbols/factory.rs index ce83718..e18014c 100644 --- a/src/symbols/factory.rs +++ b/src/symbols/factory.rs @@ -19,7 +19,9 @@ use symbols::tls::SelfSignedTlsCert; use symbols::{Symbol, SymbolRunner}; pub trait Policy { - fn user_name_for_host(&self, host_name: &'static str) -> String; + fn user_name_for_host(&self, host_name: &'static str) -> String { + host_name.split('.').rev().fold(String::new(), |result, part| if result.is_empty() { result } else { result + "_" } + part) + } fn home_for_user(&self, user_name: &str) -> String { format!("/home/{}", user_name) } @@ -27,11 +29,7 @@ pub trait Policy { 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.is_empty() { result } else { result + "_" } + part) - } -} +impl Policy for DefaultPolicy {} pub struct SymbolFactory<'a, C: 'a + CommandRunner, R: 'a + SymbolRunner, P: 'a + Policy> { command_runner: &'a C,