google_maps/client/with_reqwest_client.rs
1// =============================================================================
2
3impl crate::client::Client {
4 // -------------------------------------------------------------------------
5 //
6 /// Passes a user configured reqwest client for the Google Maps client to
7 /// use. This allows the you to have more control over the how the Google
8 /// Maps client connects to the Google Maps server.
9 ///
10 /// [Mause](https://github.com/Mause) mentioned that this feature could be
11 /// useful for writing tests. Thanks for the suggestion!
12 ///
13 /// ## Arguments
14 ///
15 /// * `reqwest_client` ‧ A reqwest client built using the
16 /// `reqwest::Client::builder()` function.
17 ///
18 /// ## Examples:
19 ///
20 /// ```rust
21 /// let reqwest_client = reqwest::Client::builder()
22 /// .user_agent("My Cool App v1.0")
23 /// .build()?;
24 ///
25 /// let mut google_maps_client = google_maps::Client::try_new("YOUR_API_KEY_HERE")
26 /// .with_reqwest_client(reqwest_client)
27 /// .build();
28 /// ```
29
30 #[cfg(all(feature = "reqwest", feature = "reqwest-middleware"))]
31 pub fn with_reqwest_client(&mut self, reqwest_client: reqwest::Client) -> &mut Self {
32 self.reqwest_client = crate::reqwest_maybe_middleware::Client::Vanilla(reqwest_client);
33 self
34 } // fn
35
36 #[cfg(all(feature = "reqwest", not(feature = "reqwest-middleware")))]
37 pub fn with_reqwest_client(&mut self, reqwest_client: reqwest::Client) -> &mut Self {
38 self.reqwest_client = reqwest_client;
39 self
40 } // fn
41
42 #[cfg(all(feature = "reqwest", feature = "reqwest-middleware"))]
43 pub fn with_reqwest_middleware_client(
44 &mut self,
45 reqwest_client: reqwest_middleware::ClientWithMiddleware
46 ) -> &mut Self {
47 self.reqwest_client = crate::reqwest_maybe_middleware::Client::Middleware(reqwest_client);
48 self
49 } // fn
50
51 #[cfg(all(feature = "reqwest", feature = "reqwest-middleware"))]
52 pub fn with_reqwest(
53 &mut self,
54 reqwest_client: crate::reqwest_maybe_middleware::Client
55 ) -> &mut Self {
56 self.reqwest_client = reqwest_client;
57 self
58 } // fn
59} // impl