aboutsummaryrefslogtreecommitdiff
path: root/lockchain-files/src/utils.rs
blob: c724d323e4ffc62e0cb87333f8a487be4c0b6d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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),
        };
    }
}