420f1ff42a
This is an improved form of the previous `error::Unexpected` type, now with more capabilities and generally better naming.
12 lines
299 B
Rust
12 lines
299 B
Rust
use std::{fs, io, path};
|
|
|
|
pub fn open_file(path: &path::Path) -> io::Result<Option<fs::File>> {
|
|
match fs::File::open(path) {
|
|
Ok(file) => Ok(Some(file)),
|
|
Err(err) => match err.kind() {
|
|
io::ErrorKind::NotFound => Ok(None),
|
|
_ => Err(err),
|
|
},
|
|
}
|
|
}
|