aboutsummaryrefslogtreecommitdiff
path: root/lockchain-files/src/utils.rs
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-09-04 16:29:03 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-09-04 16:29:03 +0200
commit0b3e6767864d3c1c7d698d3d4f383de0ae4084b6 (patch)
tree3a41e5739a0fefda3d2eec43800676a4ec078137 /lockchain-files/src/utils.rs
parent15182c1a4fd14aeda13d2d82a2294e8c7eb3a49d (diff)
Cleaning up the core a bit. Adding better (any) config handling to files
Diffstat (limited to 'lockchain-files/src/utils.rs')
-rw-r--r--lockchain-files/src/utils.rs26
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),
+ };
+ }
+}