Fix read_single parsing failure due to \n

This commit is contained in:
NGnius (Graham) 2022-07-09 12:28:33 -04:00
parent becfe89299
commit 87c5a7770b
3 changed files with 3 additions and 3 deletions

2
Cargo.lock generated
View file

@ -926,7 +926,7 @@ dependencies = [
[[package]] [[package]]
name = "usdpl-back" name = "usdpl-back"
version = "0.5.0" version = "0.5.2"
dependencies = [ dependencies = [
"bytes", "bytes",
"tokio", "tokio",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "usdpl-back" name = "usdpl-back"
version = "0.5.1" version = "0.5.3"
edition = "2021" edition = "2021"
license = "GPL-3.0-only" license = "GPL-3.0-only"
repository = "https://github.com/NGnius/usdpl-rs" repository = "https://github.com/NGnius/usdpl-rs"

View file

@ -15,7 +15,7 @@ pub fn write_single<P: AsRef<Path>, D: Display>(path: P, display: D) -> Result<(
/// Read something from a file. /// Read something from a file.
/// Useful for kernel configuration files. /// Useful for kernel configuration files.
pub fn read_single<P: AsRef<Path>, D: FromStr<Err=E>, E>(path: P) -> Result<D, (Option<io::Error>, Option<E>)> { pub fn read_single<P: AsRef<Path>, D: FromStr<Err=E>, E>(path: P) -> Result<D, (Option<io::Error>, Option<E>)> {
let mut file = File::create(path).map_err(|e| (Some(e), None))?; let mut file = File::open(path).map_err(|e| (Some(e), None))?;
let mut string = String::new(); let mut string = String::new();
file.read_to_string(&mut string).map_err(|e| (Some(e), None))?; file.read_to_string(&mut string).map_err(|e| (Some(e), None))?;
string.trim().parse().map_err(|e| (None, Some(e))) string.trim().parse().map_err(|e| (None, Some(e)))