smurf 0.1.0

SMall Useful Rust Functions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::fs::File;
use std::io::{prelude::*, BufReader};

pub fn read_to_str(path: &std::path::PathBuf) -> String {
	let file = File::open(&path);
	let file = match file {
		Ok(data) => data,
		Err(err) => {
			eprintln!("Cannot open file \"{}\"", path.display());
			std::process::exit(2)
		}
	};
	let mut buf_reader = BufReader::new(file);
	let mut content = String::new();
	buf_reader.read_to_string(&mut content).unwrap();
	content
}