Skip to content

Instantly share code, notes, and snippets.

@yaymukund
Created August 26, 2018 01:32
Show Gist options
  • Save yaymukund/0f810098390e50f9e5e7ea39dfd8d377 to your computer and use it in GitHub Desktop.
Save yaymukund/0f810098390e50f9e5e7ea39dfd8d377 to your computer and use it in GitHub Desktop.
use super::downloader::HttpClient;
use hyper::client::ResponseFuture;
use hyper::rt::Future;
use hyper::Uri;
enum DownloadStatus {
Idle,
PendingResponse,
PendingBody,
Completed,
Errored,
}
pub struct Download {
uri: String,
status: DownloadStatus,
future: ResponseFuture,
}
impl Download {
pub fn new(uri: &str, client: &HttpClient) -> Download {
let parsed_uri: Uri = uri.parse().unwrap();
Download {
uri: uri.to_owned(),
status: DownloadStatus::Idle,
future: client.get(parsed_uri),
}
}
pub fn future(&mut self) -> impl Future {
^^^^^^^^^^^ lifetime of return value does not outlive the function call
self.status = DownloadStatus::PendingResponse;
self.future.map(|res| {
self.status = if res.status().is_success() {
DownloadStatus::PendingResponse
} else {
DownloadStatus::Errored
};
res.body()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment