The following implementation seems quite simple. for some reason I don't get what the problem is. Compiler doesn't compile.
The main problem here is that I cannot change the declaration of the function test(bool) since it's out of a framework.
/// Implemented in a 3rd party framework:
trait Share {
fn dosomething();
}
impl Share for String {
fn dosomething() {
todo!()
}
}
/// My part of the implementation:
// this function `test` will be handed over (as a function) to a framework method, which I can't change it's return type.
fn test(data: bool) -> Result<impl Share, String> {
return if data {
Ok(Data {})
} else {
Ok("a string".to_string())
}
}
struct Data {
}
impl Share for Data {
fn dosomething() {
todo!()
}
}
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/lib.rs:5:12
|
5 | Ok("a string".to_string())
| ^^^^^^^^^^^^^^^^^^^^^^ expected struct `Data`, found struct `String`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error