Skip to content

Commit

Permalink
Avoid forcing user to have mut client
Browse files Browse the repository at this point in the history
  • Loading branch information
Bolognafingers committed Oct 13, 2023
1 parent fd375bc commit 36bf3b5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ impl Client {
}
}

pub fn with_url(ident: IdentificationMethod, url: Url) -> Self {
let timeout = Duration::from_secs(10);

let mut c = Self {
ident,
base_url: Url::parse("https://nominatim.openstreetmap.org/").unwrap(),
client: reqwest::ClientBuilder::new()
.timeout(timeout)
.build()
.unwrap(),
timeout,
};

c.set_base_url(url).unwrap();
c
}

/// Set the client's internal base url for all requests.
pub fn set_base_url<U: TryInto<Url>>(&mut self, url: U) -> Result<(), U::Error> {
self.base_url = url.try_into()?;
Expand Down

0 comments on commit 36bf3b5

Please sign in to comment.