diff options
Diffstat (limited to 'lockchain-files/src/utils.rs')
-rw-r--r-- | lockchain-files/src/utils.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lockchain-files/src/utils.rs b/lockchain-files/src/utils.rs new file mode 100644 index 0000000..c724d32 --- /dev/null +++ b/lockchain-files/src/utils.rs @@ -0,0 +1,26 @@ +//! Small utility module for file operations + +use std::io::{self, Read}; +use std::fs::File; + +pub fn check_config() { + +} + +/// A utility trait to read the conents from a file in +/// a single line. +pub trait FileToString { + /// Read the file contents into a string without any + /// error handling. + fn get_string(&mut self) -> Result<String, io::Error>; +} + +impl FileToString for File { + fn get_string(&mut self) -> Result<String, io::Error> { + let mut s = String::new(); + return match self.read_to_string(&mut s) { + Ok(_) => Ok(s), + Err(e) => Err(e), + }; + } +} |