Snippets Collections
let hello = warp::path!("hello" / String)
        .and(warp::any().map(move || validator.clone()))
        .and(warp::addr::remote())
        .and_then(response);

warp::serve(hello).run(([127, 0, 0, 1], 3030)).await;
async fn response(
    name: String,
    validator: Validator,
    remote: Option<SocketAddr>,
) -> Result<impl warp::Reply, warp::Rejection> {
    if let Some(addr) = remote {
        let ip_string = addr.ip().to_string();
        if validator.is_valid(ip_string.clone()).await {
            Ok(format!("Hello, {} from {}!", name, &ip_string))
        } else {
            Ok(format!("No key for {}!", &ip_string))
        }
    } else {
        Ok("No remote address!".to_string())
    }
}
let validator = Validator::new();
let path = std::path::Path::new(".env");
dotenv::from_path(path).ok();

if std::env::var("RUST_LOG").is_err() {
  std::env::set_var("RUST_LOG", "info");
}
env_logger::init();
star

Tue Aug 17 2021 16:37:54 GMT+0000 (UTC) https://rust-unofficial.github.io/patterns/intro.html

#rust #design #patterns
star

Tue Aug 17 2021 16:32:31 GMT+0000 (UTC) https://rust-lang.github.io/api-guidelines/

#rust #api
star

Thu Jul 29 2021 16:13:09 GMT+0000 (UTC) https://nnethercote.github.io/perf-book/title-page.html

#rust #performance
star

Fri Jun 04 2021 05:28:37 GMT+0000 (UTC)

#rust
star

Fri Jun 04 2021 05:27:18 GMT+0000 (UTC)

#rust
star

Fri Jun 04 2021 05:26:25 GMT+0000 (UTC)

#rust
star

Fri Jun 04 2021 05:25:20 GMT+0000 (UTC)

#rust

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension