cli_helper 0.1.7

Helper for capturing CLI input
Documentation
use std::fs::File;
use std::io::Read;

/// Try read file at path relative to program,
/// if you are not sure of the files encoding, or location (directory) use [`cli_helper::file::read_file`]
pub fn read_file_unchecked(path: &str) -> String {
    let mut v = Vec::new();
    File::open(path).unwrap().read_to_end(&mut v);
    unsafe { String::from_utf8_unchecked(v) }
}

/// Read utf-8 file at path relative to program
pub fn read_file(path: &str) -> Option<String> {
    let f = File::open(path);
    match f {
        Ok(mut f) => {
            let mut v = Vec::new();
            f.read_to_end(&mut v);
            match String::from_utf8(v) {
                Ok(s) => Some(s),
                _ => None
            }
        }
        _ => None
    }
}