diff --git a/Cargo.toml b/Cargo.toml index ccf7b0b..319d394 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ http-body-util = "0.1" bytes = "1.6" jid = { version = "0.10", features = [ "serde" ] } log = "0.4" -tokio = { version = "1", default-features = false, features = [ "rt", "net", "sync" ] } +tokio = { version = "1", default-features = false, features = [ "rt", "net", "sync", "fs" ] } pretty_env_logger = "0.5" serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" diff --git a/src/config.rs b/src/config.rs index ccb8c7e..4ef257e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -57,18 +57,17 @@ impl Config { SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 3000) } - pub fn from_file(file: Utf8PathBuf) -> Result { - if file.try_exists().is_err() { + pub async fn from_file(file: Utf8PathBuf) -> Result { + if tokio::fs::try_exists(&file).await.is_err() { let err = IoError::new(IoErrorKind::NotFound, format!("{:?} not found", file)); return Err(Error::Io(err)); } - // TODO: tokio::fs - let buf = std::fs::read_to_string(file)?; + let buf = tokio::fs::read_to_string(file).await?; Ok(toml::from_str(&buf)?) } - pub fn from_arg(file: Option<&Utf8PathBuf>) -> Result { + pub async fn from_arg(file: Option<&Utf8PathBuf>) -> Result { let path = if let Some(path) = file { // Provided by --config flag path.canonicalize_utf8()? @@ -86,6 +85,6 @@ impl Config { debug!("Using configuration file: {:?}", path); - Self::from_file(path) + Self::from_file(path).await } } diff --git a/src/main.rs b/src/main.rs index cbc261d..1af34f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ async fn main() -> Result { ) .get_matches(); - let config = Config::from_arg(matches.get_one::("config"))?; + let config = Config::from_arg(matches.get_one::("config")).await?; let (value_tx, mut value_rx) = mpsc::unbounded_channel::();