rename functions

This commit is contained in:
naskya 2024-06-21 11:08:17 +09:00
parent 6840a34d90
commit 3806262531
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
2 changed files with 11 additions and 15 deletions

View file

@ -45,7 +45,7 @@ pub(crate) enum ReadError {
InvalidFormat(#[from] toml::de::Error),
}
fn read_file_string(path: &str) -> Result<String, ReadError> {
fn read_file_as_string(path: &str) -> Result<String, ReadError> {
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<String, ReadError> {
Ok(result)
}
fn read_server_config<T>() -> Result<T, ReadError>
fn read_server_config_as<T>() -> Result<T, ReadError>
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<T>() -> Result<T, ReadError>
fn read_client_config_as<T>() -> Result<T, ReadError>
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<Revision, RevisionCheckError> {
@ -97,8 +97,8 @@ fn current_revision() -> Result<Revision, RevisionCheckError> {
config_revision: Revision,
}
let server_config_revision = read_server_config::<Config>()?.config_revision;
let client_config_revision = read_server_config::<Config>()?.config_revision;
let server_config_revision = read_server_config_as::<Config>()?.config_revision;
let client_config_revision = read_server_config_as::<Config>()?.config_revision;
if server_config_revision != client_config_revision {
return Err(RevisionCheckError::UnknownRevision(

View file

@ -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::<server::Config>() {
let server_validation_result = match read_server_config_as::<server::Config>() {
Ok(config) => config.validate().map_err(|err| {
cprintln!("<r!><bold>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::<client::Config>() {
let client_validation_result = match read_client_config_as::<client::Config>() {
Ok(config) => config.validate().map_err(|err| {
cprintln!(
"<r!><bold>{} is invalid.</></>\n{}",