It is not possible to specify sufficient type information about `_`; type annotations or general required parameter

I am trying to return an error Result with &'static str .

 impl Worker { fn get_task_by_name(&self, name: String) -> Result<Box<Task>, &'static str> { Err("Task not found!"); } } 

It produces 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?

+6
source share
1 answer

You have a parasitic semicolon after Err(...) . You tell the compiler to throw away the value you are building and return () . Of course, it does not go so far that you indicate that the return type is incorrect: it is more embarrassed that you built Result<T, E>::Err(E) without saying what T .

+11
source

All Articles