aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-18 12:47:53 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-18 12:59:35 -0400
commit1f09b3c62f40987a184c0503277b45a24251ff77 (patch)
treef5a2ea1996729a63742795941e67ad5a75b478b9
parentce81e5dcb6d48d64148cc72e9113446ae5fed1b3 (diff)
downloadteleterm-1f09b3c62f40987a184c0503277b45a24251ff77.tar.gz
teleterm-1f09b3c62f40987a184c0503277b45a24251ff77.zip
fix some deserializers
-rw-r--r--src/cmd/server.rs5
-rw-r--r--src/config.rs26
2 files changed, 23 insertions, 8 deletions
diff --git a/src/cmd/server.rs b/src/cmd/server.rs
index 97c754b..134cb9d 100644
--- a/src/cmd/server.rs
+++ b/src/cmd/server.rs
@@ -13,7 +13,10 @@ pub struct Config {
#[serde(default = "crate::config::default_connection_buffer_size")]
buffer_size: usize,
- #[serde(default = "crate::config::default_read_timeout")]
+ #[serde(
+ deserialize_with = "crate::config::read_timeout",
+ default = "crate::config::default_read_timeout"
+ )]
read_timeout: std::time::Duration,
tls_identity_file: Option<String>,
diff --git a/src/config.rs b/src/config.rs
index 0b8099c..66069db 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -27,7 +27,7 @@ pub fn listen_address<'a, D>(
where
D: serde::de::Deserializer<'a>,
{
- to_listen_address(<&str>::deserialize(deserializer)?)
+ to_listen_address(&<String>::deserialize(deserializer)?)
.map_err(serde::de::Error::custom)
}
@@ -45,7 +45,7 @@ pub fn connect_address<'a, D>(
where
D: serde::de::Deserializer<'a>,
{
- to_connect_address(<&str>::deserialize(deserializer)?)
+ to_connect_address(&<String>::deserialize(deserializer)?)
.map_err(serde::de::Error::custom)
}
@@ -73,6 +73,17 @@ pub fn default_connection_buffer_size() -> usize {
DEFAULT_CONNECTION_BUFFER_SIZE
}
+pub fn read_timeout<'a, D>(
+ deserializer: D,
+) -> std::result::Result<std::time::Duration, D::Error>
+where
+ D: serde::de::Deserializer<'a>,
+{
+ Ok(std::time::Duration::from_secs(u64::deserialize(
+ deserializer,
+ )?))
+}
+
pub fn default_read_timeout() -> std::time::Duration {
DEFAULT_READ_TIMEOUT
}
@@ -107,14 +118,13 @@ pub fn allowed_login_methods<'a, D>(
where
D: serde::de::Deserializer<'a>,
{
- Option::<Vec<&str>>::deserialize(deserializer)?
+ Option::<Vec<String>>::deserialize(deserializer)?
.map_or_else(
|| Ok(default_allowed_login_methods()),
|methods| {
methods
.iter()
- .copied()
- .map(crate::protocol::AuthType::try_from)
+ .map(|s| crate::protocol::AuthType::try_from(s.as_ref()))
.collect()
},
)
@@ -166,8 +176,10 @@ fn auth_type<'a, D>(
where
D: serde::de::Deserializer<'a>,
{
- crate::protocol::AuthType::try_from(<&str>::deserialize(deserializer)?)
- .map_err(serde::de::Error::custom)
+ crate::protocol::AuthType::try_from(
+ <String>::deserialize(deserializer)?.as_ref(),
+ )
+ .map_err(serde::de::Error::custom)
}
fn default_auth_type() -> crate::protocol::AuthType {