Created
July 11, 2019 19:48
-
-
Save rust-play/701006c875042230721c8371a4e25f0f to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
reqwest = "0.9.18" | |
tokio = "*" | |
futures = "*" | |
*/ | |
use futures::{Future, Stream, future}; | |
use reqwest::r#async::Client; | |
use tokio::runtime::current_thread::Runtime; | |
fn fetch(url: &str) -> impl Future<Item=&str, Error=()> { | |
Client::new() | |
.get(url) | |
.send() | |
.and_then(|res| { | |
res.into_body() | |
.concat2() | |
}) | |
.and_then(move |buf| { | |
future::ok(::std::str::from_utf8(&buf).unwrap()) | |
}) | |
.map_err(|err| panic!("request error: {}", err)) | |
} | |
fn main() { | |
let s = Runtime::new().unwrap().block_on(fetch("http://www.example.com/")); | |
println!("{:?}", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment