1use std::{fs::File, io::{self, BufWriter, Stdout, Write, stdout}};
2
3use crate::IoArg;
4
5pub enum Output {
7 StdOut(Stdout),
8 File(File),
9}
10
11impl Output {
12 pub fn new(io_arg: IoArg) -> io::Result<Self> {
14 let ret = match io_arg {
15 IoArg::StdStream => Output::StdOut(stdout()),
16 IoArg::File(path) => Output::File(File::create(path)?),
17 };
18 Ok(ret)
19 }
20
21 pub fn into_write(self) -> Box<dyn Write> {
25 match self {
26 Output::StdOut(stream) => Box::new(stream.lock()),
27 Output::File(file) => Box::new(BufWriter::new(file)),
28 }
29 }
30}