Skip to content
This repository was archived by the owner on Dec 10, 2022. It is now read-only.

Commit 953996e

Browse files
authored
Merge pull request #42 from tox-rs/config_update
Remove custom deserializer for log type
2 parents 1c1cff3 + 20f2448 commit 953996e

File tree

3 files changed

+22
-38
lines changed

3 files changed

+22
-38
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ log = "0.4"
2626
regex = "1"
2727
tokio = "0.1.7"
2828
tokio-codec = "0.1"
29-
config = "0.9.1"
29+
config = "0.9"
3030
serde = "1.0"
3131
serde_derive = "1.0"
3232
serde_yaml = "0.8.8"

src/node_config.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ pub struct BootstrapNode {
7070
addr: String,
7171
}
7272

73+
impl BootstrapNode {
74+
/// Resolve string address of the node to possible multiple `SocketAddr`s.
75+
pub fn resolve(&self) -> impl Iterator<Item = PackedNode> {
76+
let pk = self.pk;
77+
let addrs = match self.addr.to_socket_addrs() {
78+
Ok(addrs) => addrs,
79+
Err(e) => {
80+
warn!("Failed to resolve bootstrap node address '{}': {}", self.addr, e);
81+
Vec::new().into_iter()
82+
},
83+
};
84+
addrs.map(move |addr| PackedNode::new(addr, &pk))
85+
}
86+
}
87+
7388
fn de_from_hex<'de, D>(deserializer: D) -> Result<PublicKey, D::Error> where D: Deserializer<'de> {
7489
let s = String::deserialize(deserializer)?;
7590

@@ -79,43 +94,13 @@ fn de_from_hex<'de, D>(deserializer: D) -> Result<PublicKey, D::Error> where D:
7994
.ok_or_else(|| de::Error::custom("Can't make PublicKey"))
8095
}
8196

82-
// TODO: Remove this function. Use default String type after bug fix released.
83-
// Bug is here `https://github.com/mehcode/config-rs/issues/74`
84-
fn de_log_type<'de, D>(deserializer: D) -> Result<LogType, D::Error> where D: Deserializer<'de> {
85-
let s = String::deserialize(deserializer)?;
86-
87-
match &s[..] {
88-
"Stderr" => Ok(LogType::Stderr),
89-
"Stdout" => Ok(LogType::Stdout),
90-
#[cfg(unix)]
91-
"Syslog" => Ok(LogType::Syslog),
92-
"None" => Ok(LogType::None),
93-
other => Err(de::Error::custom(format!("log-type: invalid value '{}'", other))),
94-
}
95-
}
96-
9797
fn de_threads<'de, D>(deserializer: D) -> Result<Threads, D::Error> where D: Deserializer<'de> {
9898
let s = String::deserialize(deserializer)?;
9999

100100
Threads::from_str(&s)
101101
.map_err(|e| de::Error::custom(format!("threads: {:?}", e)))
102102
}
103103

104-
impl BootstrapNode {
105-
/// Resolve string address of the node to possible multiple `SocketAddr`s.
106-
pub fn resolve(&self) -> impl Iterator<Item = PackedNode> {
107-
let pk = self.pk;
108-
let addrs = match self.addr.to_socket_addrs() {
109-
Ok(addrs) => addrs,
110-
Err(e) => {
111-
warn!("Failed to resolve bootstrap node address '{}': {}", self.addr, e);
112-
Vec::new().into_iter()
113-
},
114-
};
115-
addrs.map(move |addr| PackedNode::new(addr, &pk))
116-
}
117-
}
118-
119104
/// Config parsed from command line arguments.
120105
#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
121106
pub struct NodeConfig {
@@ -147,7 +132,6 @@ pub struct NodeConfig {
147132
#[serde(deserialize_with = "de_threads")]
148133
pub threads: Threads,
149134
/// Specifies where to write logs.
150-
#[serde(deserialize_with = "de_log_type")]
151135
#[serde(rename = "log-type")]
152136
pub log_type: LogType,
153137
/// Message of the day

0 commit comments

Comments
 (0)