Skip to content
← Blog

Hello World

Thoughts with no themes and no expectations — just exporting for the benefit, or detriment, of others.

Intro

blahblah!();

This is where I will keep my thoughts I want to share with others. No themes, no expectations. Just me exporting for the benefit, or detriment, of others.

#shoutout to my editor #grok.

I leave you with a thought:

Rust did it right with enum impls and match with Result.

A tokio example found in Dist | Match a Tokio Result

use std::time::Duration;

use tokio::time::timeout;

#[derive(Debug)]
pub enum FetchError {
    TimedOut,
    Io(std::io::Error),
}

pub async fn fetch_with_deadline(url: &str) -> Result<String, FetchError> {
    let work = async {
        // stand-in for reqwest / hyper / custom client
        Ok::<_, std::io::Error>(format!("body from {url}"))
    };

    match timeout(Duration::from_secs(2), work).await {
        Ok(Ok(body)) => Ok(body),
        Ok(Err(e)) => Err(FetchError::Io(e)),
        Err(_elapsed) => Err(FetchError::TimedOut),
    }
}

#[tokio::main]
async fn main() {
    match fetch_with_deadline("https://example.com").await {
        Ok(body) => println!("ok: {body}"),
        Err(FetchError::TimedOut) => eprintln!("request timed out"),
        Err(FetchError::Io(e)) => eprintln!("io failed: {e}"),
    }
}

I’ll write more things later.

Dan

cmdshftp