Hello!
I learn Rust and try to make a Google OAuth 2.0 client for practice. I use hyper library as https client and i got some questions about it types and templates.
I wrote this code but it doesn't compile because of retrieve_url function return type.
fn retrieve_auth_url() {
let (sender, receiver) = futures::sync::oneshot::channel::<Url>();
hyper::rt::run(hyper::rt::lazy(move || {
retrieve_url(sender)
}));
let location = receiver.wait();
println!("Response: {:?}", location);
}
fn retrieve_url(send: Sender<Url>) -> Client<HttpsConnector<Error>> {
let uri = Url::parse_with_params(GOOGLE_AUTH_URL, [
("client_id", CLIENT_ID),
("redirect_uri", "http://[::1]:3000"),
("response_type", "code"),
("scope", "https://www.googleapis.com/auth/drive")
].iter());
let url = uri.unwrap().as_str().parse::<Uri>().unwrap();
let https = HttpsConnector::new(1).unwrap();
let client = Client::builder().build::<_, hyper::Body>(https);
client.get(url)
.map(|res| {
Url::parse(res.headers().get("location").unwrap().to_str().unwrap()).unwrap()
})
.map_err(|err| {
err
})
}
If I embed retrieve_url body into closure - everything works. Which type should be there? And why MapErr type can be used as a parameter for lazy function? I understand it implement Future trait but it isn't a Client! But hyper::rt::run should run Client exactly!
Thank you!