I'm trying to return an error Result with a &'static str
.
impl Worker {
fn get_task_by_name(&self, name: String) -> Result<Box<Task>, &'static str> {
Err("Task not found!");
}
}
It outputs the following error:
src/lib.rs:84:5: 84:8 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
src/lib.rs:84 Err("Task not found!");
^~~
What could be the problem here?
You have a spurious semicolon after the Err(...)
. You're telling the compiler to throw away the value you construct and return ()
instead. Of course, it doesn't get as far as telling you the return type is wrong: it's more immediately confused by the fact that you've constructed a Result<T, E>::Err(E)
without telling it what T
is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With