From e160df07519630da30c856633f981ca58e809ca7 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Thu, 17 Dec 2020 15:46:43 +0800 Subject: [PATCH] Make read_i64_from private and merge read_str_from to its caller Also remove duplicated read_i64_from. Signed-off-by: Tim Zhang --- src/lib.rs | 18 ++++++++---------- src/memory.rs | 12 +----------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1205be..9253c34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -219,7 +219,13 @@ mod sealed { } fn get(&self, key: &str) -> Result { - 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 Result { +fn read_i64_from(mut file: File) -> Result { 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 { Err(e) => Err(Error::with_cause(ReadFailed, e)), } } - -pub fn read_str_from(mut file: File) -> Result { - 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)), - } -} diff --git a/src/memory.rs b/src/memory.rs index 6243a15..04fd908 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -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 { } } -fn read_i64_from(mut file: File) -> Result { - 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 { let mut string = String::new(); match file.read_to_string(&mut string) {