Write license info from file

This commit is contained in:
2022-11-16 03:35:28 +01:00
parent 0b5e67582d
commit 3d9e87a400
4 changed files with 54 additions and 23 deletions

View File

@@ -3,8 +3,9 @@ use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
pub mod bits;
pub mod raw;
pub type Output = Box<dyn Write>;
pub type Input = Box<dyn Read>;
pub type BufferedInputFile = BufReader<std::fs::File>;
pub type Output = Box<dyn Write>;
pub type Input = Box<dyn Read>;
pub trait ErrorString {
fn to_string(self) -> String;
@@ -113,11 +114,15 @@ pub fn open_output(output_file: Option<PathBuf>) -> Result<Output, Error> {
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input, Error> {
match input_file {
Some(input_path) => Ok(Box::new(BufReader::new(std::fs::File::open(input_path)?))),
Some(input_path) => Ok(Box::new(open_input_file_buffered(&input_path)?)),
None => Ok(Box::new(BufReader::new(std::io::stdin()))),
}
}
pub fn open_input_file_buffered(input_path: &PathBuf) -> Result<BufferedInputFile, Error> {
Ok(BufReader::new(std::fs::File::open(input_path)?))
}
pub fn os_str_to_string(input: &std::ffi::OsStr, name: &str) -> Result<String, Error> {
Ok(Error::ok_or_new(input.to_str(), ||format!("Converting {} to UTF-8 failed", name))?.to_owned())
}