@@ -10,6 +10,7 @@ use std::collections::HashMap;
1010use std:: fs:: { self , File } ;
1111use std:: io:: { BufRead , BufReader , Read , Write } ;
1212use std:: path:: { Path , PathBuf } ;
13+ use std:: str:: FromStr ;
1314
1415macro_rules! update_and_test {
1516 ( $self: ident, $set_func: ident, $value: expr, $get_func: ident) => {
@@ -832,14 +833,35 @@ pub fn nested_keyed_to_hashmap(mut file: File) -> Result<HashMap<String, HashMap
832833 Ok ( h)
833834}
834835
835- /// read and parse an i64 data
836- fn read_i64_from ( mut file : File ) -> Result < i64 > {
836+ fn read_from < T > ( mut file : File ) -> Result < T >
837+ where
838+ T : FromStr ,
839+ <T as FromStr >:: Err : ' static + Send + Sync + std:: error:: Error ,
840+ {
837841 let mut string = String :: new ( ) ;
838842 match file. read_to_string ( & mut string) {
839843 Ok ( _) => string
840844 . trim ( )
841- . parse ( )
845+ . parse :: < T > ( )
842846 . map_err ( |e| Error :: with_cause ( ParseError , e) ) ,
843847 Err ( e) => Err ( Error :: with_cause ( ReadFailed , e) ) ,
844848 }
845849}
850+
851+ fn read_string_from ( mut file : File ) -> Result < String > {
852+ let mut string = String :: new ( ) ;
853+ match file. read_to_string ( & mut string) {
854+ Ok ( _) => Ok ( string. trim ( ) . to_string ( ) ) ,
855+ Err ( e) => Err ( Error :: with_cause ( ReadFailed , e) ) ,
856+ }
857+ }
858+
859+ /// read and parse an u64 data
860+ fn read_u64_from ( file : File ) -> Result < u64 > {
861+ read_from :: < u64 > ( file)
862+ }
863+
864+ /// read and parse an i64 data
865+ fn read_i64_from ( file : File ) -> Result < i64 > {
866+ read_from :: < i64 > ( file)
867+ }
0 commit comments