fn open_files(
    input_file: Option<PathBuf>,
    output_file: Option<PathBuf>,
) -> (Box<dyn Read>, Box<dyn Write>) {
    let input: Box<dyn Read> = match input_file {
        Some(path) => {
            let file = File::open(path).expect("failed to open input file");
            Box::new(BufReader::new(file))
        }
        None => Box::new(io::stdin()),
    };

    let output: Box<dyn Write> = match output_file {
        Some(path) => {
            let file = File::create(path).expect("failed to open output file");
            Box::new(file)
        }
        None => Box::new(io::stdout()),
    };

    (input, output)
}
/// Opens the given input and output files.
///
/// If either file is missing, it is replaced with stdin or stdout, respectively.
Opens the given input and output files.
If either file is missing, it is replaced with stdin or stdout, respectively.
Opens the given input and output files . If either file is missing it is replaced with stdin or stdout respectively .
fn open_files(
    input_file: Option<PathBuf>,
    output_file: Option<PathBuf>,
) -> (Box<dyn Read>, Box<dyn Write>) {
    let input: Box<dyn Read> = match input_file {
        Some(path) => {
            let file = File::open(path).expect("failed to open input file");
            Box::new(BufReader::new(file))
        }
        None => Box::new(io::stdin()),
    };
    let output: Box<dyn Write> = match output_file {
        Some(path) => {
            let file = File::create(path).expect("failed to open output file");
            Box::new(file)
        }
        None => Box::new(io::stdout()),
    };
    (input, output)
}
fn open_files ( input_file : Option < PathBuf > , output_file : Option < PathBuf > , ) -> ( Box < dyn Read > , Box < dyn Write > ) { let input : Box < dyn Read > = match input_file { Some ( path ) => { let file = File :: open ( path ) . expect ( " " ) ; Box :: new ( BufReader :: new ( file ) ) } None => Box :: new ( io :: stdin ( ) ) , } ; let output : Box < dyn Write > = match output_file { Some ( path ) => { let file = File :: create ( path ) . expect ( " " ) ; Box :: new ( file ) } None => Box :: new ( io :: stdout ( ) ) , } ; ( input , output ) }
Opens the given input and output files.
Opens the given input and output files .
input_file
Option<PathBuf>
output_file
Option<PathBuf>
input_file
Option<PathBuf>
output_file
Option<PathBuf>