From 4fb8b93bf33f5f13cd0d40b12e966c806c322730 Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 4 Jan 2024 10:00:48 +0800 Subject: [PATCH] support creating client with configuration --- rust/src/client.rs | 5 +++++ rust/src/common/config.rs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/rust/src/client.rs b/rust/src/client.rs index 25bc7d8..3ed6485 100644 --- a/rust/src/client.rs +++ b/rust/src/client.rs @@ -115,6 +115,11 @@ impl Client { Self::with_config(&parsed_url, Configuration::new()?) } + pub fn new_with_config(url: &str, configuration: Configuration) -> Result { + let parsed_url = Url::parse(url)?; + Self::with_config(&parsed_url, configuration) + } + fn with_config(url: &Url, config: Configuration) -> Result { if !url.has_host() { return Err(HdfsError::InvalidArgument( diff --git a/rust/src/common/config.rs b/rust/src/common/config.rs index 9895bc2..754db01 100644 --- a/rust/src/common/config.rs +++ b/rust/src/common/config.rs @@ -21,6 +21,14 @@ pub struct Configuration { map: HashMap, } +impl From> for Configuration { + fn from(conf_map: HashMap) -> Self { + Self { + map: conf_map, + } + } +} + impl Configuration { pub fn new() -> io::Result { let mut map: HashMap = HashMap::new();