From bc18173ffa6250427462489202cd950daad1f447 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 31 Jan 2020 10:19:10 +0000 Subject: [PATCH] Made builder methods on config more generic to accept any kind of strings --- nym-client/src/commands/init.rs | 4 ++-- nym-client/src/commands/run.rs | 4 ++-- nym-client/src/config/mod.rs | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/nym-client/src/commands/init.rs b/nym-client/src/commands/init.rs index 6888de474e..f8cea00742 100644 --- a/nym-client/src/commands/init.rs +++ b/nym-client/src/commands/init.rs @@ -7,11 +7,11 @@ use pemstore::pemstore::PemStore; pub fn execute(matches: &ArgMatches) { println!("Initialising client..."); - let id = matches.value_of("id").unwrap().to_string(); // required for now + let id = matches.value_of("id").unwrap(); // required for now let mut config = crate::config::Config::new(id); if let Some(provider_id) = matches.value_of("provider") { - config = config.with_provider_id(provider_id.to_string()); + config = config.with_provider_id(provider_id); } let mix_identity_keys = MixIdentityKeyPair::new(); diff --git a/nym-client/src/commands/run.rs b/nym-client/src/commands/run.rs index d6aadeb965..1c5398d255 100644 --- a/nym-client/src/commands/run.rs +++ b/nym-client/src/commands/run.rs @@ -15,11 +15,11 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to load config file"); if let Some(directory) = matches.value_of("directory") { - config_file = config_file.with_custom_directory(directory.to_string()); + config_file = config_file.with_custom_directory(directory); } if let Some(provider_id) = matches.value_of("provider") { - config_file = config_file.with_provider_id(provider_id.to_string()); + config_file = config_file.with_provider_id(provider_id); } if let Some(socket_type) = matches.value_of("socket-type") { diff --git a/nym-client/src/config/mod.rs b/nym-client/src/config/mod.rs index 2e8dd80952..ad4f73a2b8 100644 --- a/nym-client/src/config/mod.rs +++ b/nym-client/src/config/mod.rs @@ -64,11 +64,12 @@ impl NymConfig for Config { } impl Config { - pub fn new(id: String) -> Self { + pub fn new>(id: S) -> Self { Config::default().with_id(id) } - pub fn with_id(mut self, id: String) -> Self { + pub fn with_id>(mut self, id: S) -> Self { + let id = id.into(); if self.client.private_identity_key_file.as_os_str().is_empty() { self.client.private_identity_key_file = self::Client::default_private_identity_key_file(&id); @@ -81,18 +82,18 @@ impl Config { self } - pub fn with_provider_id(mut self, id: String) -> Self { - self.client.provider_id = id; + pub fn with_provider_id>(mut self, id: S) -> Self { + self.client.provider_id = id.into(); self } - pub fn with_provider_auth_token(mut self, token: String) -> Self { - self.client.provider_authtoken = Some(token); + pub fn with_provider_auth_token>(mut self, token: S) -> Self { + self.client.provider_authtoken = Some(token.into()); self } - pub fn with_custom_directory(mut self, directory_server: String) -> Self { - self.client.directory_server = directory_server; + pub fn with_custom_directory>(mut self, directory_server: S) -> Self { + self.client.directory_server = directory_server.into(); self }