diff --git a/Cargo.lock b/Cargo.lock index 8d56e42..228dbf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1037,7 +1037,7 @@ dependencies = [ [[package]] name = "usdpl-back" -version = "0.7.2" +version = "0.8.0" dependencies = [ "async-recursion", "async-trait", diff --git a/usdpl-back/Cargo.toml b/usdpl-back/Cargo.toml index debb2a5..908d2b4 100644 --- a/usdpl-back/Cargo.toml +++ b/usdpl-back/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "usdpl-back" -version = "0.7.2" +version = "0.8.0" edition = "2021" license = "GPL-3.0-only" repository = "https://github.com/NGnius/usdpl-rs" diff --git a/usdpl-back/src/api_common/files.rs b/usdpl-back/src/api_common/files.rs index f159b35..cb7b890 100644 --- a/usdpl-back/src/api_common/files.rs +++ b/usdpl-back/src/api_common/files.rs @@ -12,11 +12,19 @@ pub fn write_single, D: Display>(path: P, display: D) -> Result<( write!(file, "{}", display) } +/// read_single error +pub enum ReadError { + /// IO Error + Io(io::Error), + /// String parsing error + Parse(E), +} + /// Read something from a file. /// Useful for kernel configuration files. -pub fn read_single, D: FromStr, E>(path: P) -> Result, Option)> { - let mut file = File::open(path).map_err(|e| (Some(e), None))?; +pub fn read_single, D: FromStr, E>(path: P) -> Result> { + let mut file = File::open(path).map_err(ReadError::Io)?; let mut string = String::new(); - file.read_to_string(&mut string).map_err(|e| (Some(e), None))?; - string.trim().parse().map_err(|e| (None, Some(e))) + file.read_to_string(&mut string).map_err(ReadError::Io)?; + string.trim().parse().map_err(ReadError::Parse) }