try it on linux

This commit is contained in:
Jon Janzen
2021-08-21 18:15:47 -06:00
parent f292f9cc2d
commit 758efbe61a
3 changed files with 639 additions and 30 deletions

View File

@@ -1,19 +1,36 @@
use color_eyre::Report;
use reqwest::Client;
use tokio::time::sleep;
use std::time::Duration;
use tracing::info;
use tracing_subscriber::EnvFilter;
mod dumb;
pub const URL_1: &str = "https://fasterthanli.me/articles/whats-in-the-box";
pub const URL_2: &str = "https://fasterthanli.me/series/advent-of-code-2020/part-13";
fn type_name_of<T>(_: &T) -> &'static str {
std::any::type_name::<T>()
}
#[tokio::main]
async fn main() -> Result<(), Report> {
setup()?;
info!("Hello, from a yet to be necessary async runtime");
info!("Building that fetch future...");
let client = Client::new();
let fut = fetch_thing(&client, URL_1);
info!("Sleeping for a bit...");
sleep(Duration::from_secs(1)).await;
info!("Awaiting that fetch future...");
fut.await?;
info!("Done awaiting that fetch future");
Ok(())
}
fn setup() -> Result<(), Report> {
if std::env::var("RUST_BACKTRACE").is_err() {
std::env::set_var("RUST_BACKTRACE", "1")
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
std::env::set_var("RUST_LIB_BACKTRACE", "1")
}
color_eyre::install()?;
@@ -26,3 +43,21 @@ fn setup() -> Result<(), Report> {
Ok(())
}
// async fn fetch_thing(client: &Client, url: &str) -> Result<(), Report> {
// let res = client.get(url).send().await?.error_for_status()?;
// info!(%url, content_type = ?res.headers().get("content-type"), "Got a response!");
// Ok(())
// }
//
use std::future::Future;
fn fetch_thing<'a> (
client: &'a Client,
url: &'a str,
) -> impl Future<Output = Result<(), Report>> + 'a {
async move {
let res = client.get(url).send().await?.error_for_status()?;
info!(%url, content_type = ?res.headers().get("content-type"), "Got a response!");
Ok(())
}
}