georust/geocoding

"cannot resolve "_: num_traits::float::Float" error during compiling for forward search

mtmail opened this issue · 2 comments

I'm trying to get a forward search going with version 0.0.3, similar to the test code in
https://github.com/georust/geocoding/blob/master/src/opencage.rs#L648

use geocoding::{Opencage, Forward};

fn main() {
    let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
    let address = "Schwabing, München";
    let res = oc.forward(&address);
    println!("{:?}", res.unwrap());
}

Compiling via cargo build returns

   Compiling test-rust-geocode v0.1.0 (/private/tmp/test-rust-geocode)
error[E0283]: type annotations required: cannot resolve `_: num_traits::float::Float`
  --> src/main.rs:35:18
   |
35 |     let res = oc.forward(&address);
   |                  ^^^^^^^

Reverse search works and I can't see an obvious difference in how forward and reverse are implemented. I tried importing the num_trait module. Is there anything I'm missing in my code?

Rust/Cargo version 1.33.0

thanks a lot

Because forward returns a vector of generic points (Point<T>), the compiler needs to know what type you want T to be, so you need to specify it explicitly with a type annotation:

use geocoding::{Opencage, Forward, Point};

fn main() {
    let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
    let address = "Schwabing, München";
    let res: Vec<Point<f64>> = oc.forward(&address).unwrap();
    println!("{:?}", res);
}

I'll try to clarify this in the doc example. Let me know if you need any other help!

@frewsxcv Thanks a lot!