Make read_i64_from private and merge read_str_from to its caller

Also remove duplicated read_i64_from.

Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
Tim Zhang
2020-12-17 15:46:43 +08:00
parent e1e05d3a1c
commit e160df0751
2 changed files with 9 additions and 21 deletions

View File

@@ -219,7 +219,13 @@ mod sealed {
}
fn get(&self, key: &str) -> Result<String> {
self.open_path(key, false).and_then(read_str_from)
self.open_path(key, false).and_then(|mut file: File| {
let mut string = String::new();
match file.read_to_string(&mut string) {
Ok(_) => Ok(string.trim().to_owned()),
Err(e) => Err(Error::with_cause(ReadFailed, e)),
}
})
}
}
}
@@ -827,7 +833,7 @@ pub fn nested_keyed_to_hashmap(mut file: File) -> Result<HashMap<String, HashMap
}
/// read and parse an i64 data
pub fn read_i64_from(mut file: File) -> Result<i64> {
fn read_i64_from(mut file: File) -> Result<i64> {
let mut string = String::new();
match file.read_to_string(&mut string) {
Ok(_) => string
@@ -837,11 +843,3 @@ pub fn read_i64_from(mut file: File) -> Result<i64> {
Err(e) => Err(Error::with_cause(ReadFailed, e)),
}
}
pub fn read_str_from(mut file: File) -> Result<String> {
let mut string = String::new();
match file.read_to_string(&mut string) {
Ok(_) => Ok(string.trim().to_owned()),
Err(e) => Err(Error::with_cause(ReadFailed, e)),
}
}

View File

@@ -17,6 +17,7 @@ use std::sync::mpsc::Receiver;
use crate::error::ErrorKind::*;
use crate::error::*;
use crate::events;
use crate::read_i64_from;
use crate::flat_keyed_to_hashmap;
@@ -880,17 +881,6 @@ fn read_u64_from(mut file: File) -> Result<u64> {
}
}
fn read_i64_from(mut file: File) -> Result<i64> {
let mut string = String::new();
match file.read_to_string(&mut string) {
Ok(_) => string
.trim()
.parse()
.map_err(|e| Error::with_cause(ParseError, e)),
Err(e) => Err(Error::with_cause(ReadFailed, e)),
}
}
fn read_string_from(mut file: File) -> Result<String> {
let mut string = String::new();
match file.read_to_string(&mut string) {