This
use backoff::{retry, Error, ExponentialBackoff};
fn test() -> Result<AuthResponse, String> {
let op = || {
reqwest::blocking::Client::new()
.post("https://blah.com")
.send()
.map_err(Error::transient)
};
retry(ExponentialBackoff::default(), op)
.map_err(|e| e.to_string())
.and_then(|r| r.json::<AuthResponse>())
}
results in (cargo check)
147 | fn test() -> Result<AuthResponse, String> {
| ---------------------------- expected `Result<_, std::string::String>` because of return type
...
157 | .and_then(|r| r.json::<AuthResponse>())
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<_, String>`, found `Result<AuthResponse, Error>`
|
= note: expected enum `Result<_, std::string::String>`
found enum `Result<AuthResponse, reqwest::Error>`
The code transforms the error twice - in the closure, to backoff::Error, and then with map_err on the return value of retry
, to String. How is it still a reqwest::Error
at the point of that call?
These combinators don't seem to work as one would expect. This is very unintuitive.