leontoeides / google_maps

An unofficial Google Maps Platform client library for the Rust programming language.
https://crates.io/crates/google_maps
Apache License 2.0
59 stars 24 forks source link

Method execute not found in &mut DirectionsRequest<'_> #28

Closed emirror-de closed 2 months ago

emirror-de commented 2 months ago

Dear Maintainer,

I created a binary in the examples folder to test the example from the docs of the directions API. But I do get the following error message when trying to compile:

Compiling req v0.1.0 (/home/projects/google_maps/examples/req)
error[E0599]: no method named `execute` found for mutable reference `&mut DirectionsRequest<'_>` in the current scope
  --> examples/req/src/main.rs:16:2
   |
9  |   let directions = google_maps_client.directions(
   |  __________________-
10 | |     // Origin: Canadian Museum of Nature
11 | |     Location::from_address("240 McLeod St, Ottawa, ON K2P 2R1"),
12 | |     // Destination: Canada Science and Technology Museum
...  |
15 | | .with_travel_mode(TravelMode::Driving)
16 | | .execute()
   | | -^^^^^^^ method not found in `&mut DirectionsRequest<'_>`
   | |_|
   |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `req` (bin "req") due to 1 previous error

According to the docs, the method should be available. Can you give me a hint what I am doing wrong?

I pushed the used code to a fork here.

emirror-de commented 2 months ago

Ah I found something: Removing default-features = false, features = ["directions", "reqwest", "rustls", "brotli"] from Cargo.toml compiles without error.

It seems that there is some interference in the feature flags?

leontoeides commented 2 months ago

Hey, it sounds like you mostly figured it out.

If you look under "Feature flag usage example" in the README.md there's an example.

Going from memory, I believe (?) at the time, one could not have a feature name with the same name as a crate dependency. So, the feature was called enable-reqwest rather than the expected reqwest.

Try using enable-reqwest instead and let me know if this works for you.

When the default features are disabled, one must explicitly say they want to use the reqwest crate by using the enable-reqwest feature, which will in-turn give access to the execute method.

If the enable-reqwest feature is not defined, one must manually forward the query string to the desired HTTP crate like so:

// Get query string from builder pattern:
let query_url = google_maps_client.time_zone(
     LatLng::try_from_dec(dec!(50.090_903), dec!(14.400_512))?,
     Utc::now()
).query_url();

// Insert your favourite HTTP client here:
let json = reqwest::get(query_url).await?.text().await?;

// Parse JSON string into a TimeZoneResponse structure:
let time_zone: TimeZoneResponse = json.parse()?;

This is useful if you would like to use a crate other than reqwest or if this crate is being used in a Web Assembly (WASM) application

emirror-de commented 2 months ago

Hey thanks for your response and explanations! I managed to make it work now, somehow I seem to used it the wrong way :D