3 ms·
The only way I can figure out to make this explicit, though, seems very verbose and non-intuitive and frankly no clearer than `.into()` on its own: Err(Into::<
by jamincan 4y ago
The only way I can figure out to make this explicit, though, seems very verbose and non-intuitive and frankly no clearer than `.into()` on its own:
Err(Into::<Box<dyn Error>>::into("sha1 hash is not valid"))
Is there a better way to constrain the trait implementation of Into?
- andrewaylett 4y agoYou can (although I wouldn't recommend it) be explicit about the type using 'as': Err("sha1 hash is not valid".into()) as Result<(), Box<dyn Error>> Or I'd often reach for an intermediate variable before a turbofish: let e: Box<dyn Error> = "".into(); Err(e) The 'as' trick is useful for helping the compiler to understand the return of a lambda where you need it to coerce errors to a specific type.