Browse Source

Simplify DefaultPolicy

master
Adrian Heine 5 years ago
parent
commit
54458709f9
  1. 10
      src/symbols/factory.rs

10
src/symbols/factory.rs

@ -19,7 +19,9 @@ use symbols::tls::SelfSignedTlsCert;
use symbols::{Symbol, SymbolRunner}; use symbols::{Symbol, SymbolRunner};
pub trait Policy { 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 { fn home_for_user(&self, user_name: &str) -> String {
format!("/home/{}", user_name) format!("/home/{}", user_name)
} }
@ -27,11 +29,7 @@ pub trait Policy {
pub struct DefaultPolicy; 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> { pub struct SymbolFactory<'a, C: 'a + CommandRunner, R: 'a + SymbolRunner, P: 'a + Policy> {
command_runner: &'a C, command_runner: &'a C,

Loading…
Cancel
Save