You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to keep same instance of reqwest::Client between tile fetches. This should alow keeping the connection open between tile fetches and would allow local caching with e.g. http-cache-reqwest crate. In general keeping some kind of state between tile fetches would be useful.
AFAIK the API needs changes to allow this.
Currently I'm trying to do it as:
let http_client = Arc::new(ClientBuilder::new().build()?);let client2 = http_client.clone();let fetcher = |x, y, zoom| tile_fetcher(client2, x, y, zoom);let snapr = snapr::SnaprBuilder::new().with_tile_fetcher(snapr::TileFetcher::Individual(&fetcher)).build()?;
and the compiler error I get is:
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
--> mapper/src/lib.rs:20:23
|
20 | let fetcher = |x, y, zoom| tile_fetcher(client2, x, y, zoom);
| ^^^^^^^^^^^^ ------- closure is `FnOnce` because it moves the variable `client2` out of its environment
| |
| this closure implements `FnOnce`, not `Fn`
21 | let snapr = snapr::SnaprBuilder::new()
22 | .with_tile_fetcher(snapr::TileFetcher::Individual(&fetcher))
| -------- the requirement to implement `Fn` derives from here
|
= note: required for the cast from `&{closure@smeshty-mapper/src/lib.rs:20:23: 20:35}` to `&dyn Fn(i32, i32, u8) -> Result<DynamicImage, snapr::Error> + Sync`
The text was updated successfully, but these errors were encountered:
Although, I realize the above example is not ideal for a lot of cases. I do really like the idea of having a more stateful TileFetcher variant, do you think a variant that allows you to pass in an object that implements something akin to a TileFetcher trait would work well for your case? Maybe something like the following?
I would like to keep same instance of
reqwest::Client
between tile fetches. This should alow keeping the connection open between tile fetches and would allow local caching with e.g. http-cache-reqwest crate. In general keeping some kind of state between tile fetches would be useful.AFAIK the API needs changes to allow this.
Currently I'm trying to do it as:
and the compiler error I get is:
The text was updated successfully, but these errors were encountered: