E0283 type annotations required

Hi guys, can anyone explain me why the following code is not compiling and how I can fixed?
The error I got is

error[E0283]: type annotations required: cannot resolve `Ts: std::convert::Into<_>`
pub struct Ts;

impl Ts{
    fn new()->Ts{
        Ts{}
    }
}

impl Into<f64> for Ts {
    fn into(self) -> f64 {
        0.0f64
    }
}

fn main(){
    let ts:Ts = Ts::new();
    ts.into();
}

You can see the code on the rust playground:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=d341c9cb655145c02761d38664e4d9de

Thank you very much for your time!

Rust does not know which type you want to convert Ts to. Try let v: f64 = ts.into();.

You may think it’s obvious there’s only one option, but there is also a default into implementation in the std, so the compiler sees multiple possible conversions and wants you to specify which one you want.

1 Like

I got it,
thank you very much guys