From 380626253186bce2b4ad6959463c076ead5957fc Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 21 Jun 2024 11:08:17 +0900 Subject: [PATCH] rename functions --- src/command/config.rs | 14 +++++++------- src/command/config/validate.rs | 12 ++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/command/config.rs b/src/command/config.rs index 4c385e1..3139ce3 100644 --- a/src/command/config.rs +++ b/src/command/config.rs @@ -45,7 +45,7 @@ pub(crate) enum ReadError { InvalidFormat(#[from] toml::de::Error), } -fn read_file_string(path: &str) -> Result { +fn read_file_as_string(path: &str) -> Result { let mut file = fs::File::open(path)?; let mut result = String::new(); file.read_to_string(&mut result)?; @@ -53,18 +53,18 @@ fn read_file_string(path: &str) -> Result { Ok(result) } -fn read_server_config() -> Result +fn read_server_config_as() -> Result where T: serde::de::DeserializeOwned, { - toml::from_str(&read_file_string(SERVER_CONFIG_PATH)?).map_err(ReadError::InvalidFormat) + toml::from_str(&read_file_as_string(SERVER_CONFIG_PATH)?).map_err(ReadError::InvalidFormat) } -fn read_client_config() -> Result +fn read_client_config_as() -> Result where T: serde::de::DeserializeOwned, { - toml::from_str(&read_file_string(CLIENT_CONFIG_PATH)?).map_err(ReadError::InvalidFormat) + toml::from_str(&read_file_as_string(CLIENT_CONFIG_PATH)?).map_err(ReadError::InvalidFormat) } fn current_revision() -> Result { @@ -97,8 +97,8 @@ fn current_revision() -> Result { config_revision: Revision, } - let server_config_revision = read_server_config::()?.config_revision; - let client_config_revision = read_server_config::()?.config_revision; + let server_config_revision = read_server_config_as::()?.config_revision; + let client_config_revision = read_server_config_as::()?.config_revision; if server_config_revision != client_config_revision { return Err(RevisionCheckError::UnknownRevision( diff --git a/src/command/config/validate.rs b/src/command/config/validate.rs index 44b90e7..7ff8da0 100644 --- a/src/command/config/validate.rs +++ b/src/command/config/validate.rs @@ -1,11 +1,7 @@ //! `config validate` subcommand -use crate::{ - command::config::{ - current_revision, read_client_config, read_server_config, ReadError, RevisionCheckError, - }, - config::{client, server, CLIENT_CONFIG_PATH, SERVER_CONFIG_PATH}, -}; +use super::*; +use crate::config::{client, server, CLIENT_CONFIG_PATH, SERVER_CONFIG_PATH}; use color_print::cprintln; use enum_iterator::Sequence; use validator::Validate; @@ -29,7 +25,7 @@ pub(super) fn run() -> Result<(), ValidationError> { return Err(ValidationError::OutOfDate); } - let server_validation_result = match read_server_config::() { + let server_validation_result = match read_server_config_as::() { Ok(config) => config.validate().map_err(|err| { cprintln!("config/server.toml is invalid.\n{}", err); ValidationError::InvalidConfig @@ -41,7 +37,7 @@ pub(super) fn run() -> Result<(), ValidationError> { Err(ReadError::ReadFile(err)) => Err(ValidationError::ReadFile(err)), }; - let client_validation_result = match read_client_config::() { + let client_validation_result = match read_client_config_as::() { Ok(config) => config.validate().map_err(|err| { cprintln!( "{} is invalid.\n{}",