I have function that returns a Result
and I am using the ?
operation on it. What is the catch?
Function:
pub fn open(filename: &str) -> Result<Box<TIFF>> {
let tiff_reader = TIFFReader;
tiff_reader.load(filename)
}
MRE:
use geotiff::TIFF;
fn main() {
let res = TIFF::open("geotiff.tif")?;
println!("Hello, world!");
}
Compiler:
the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
cannot use the `?` operator in a function that returns `()`
help: the trait `std::ops::Try` is not implemented for `()`
note: required by `std::ops::Try::from_error`rustc(E0277)