Skip to content

Instantly share code, notes, and snippets.

View max-itzpapalotl's full-sized avatar

max-itzpapalotl

View GitHub Profile
@max-itzpapalotl
max-itzpapalotl / warp2.md
Last active February 25, 2024 14:46
26. An HTTP server using warp II

26. An HTTP server using warp II

Preparations

We need to add the following dependencies:

cargo add tokio --features full
cargo add warp
cargo add serde_json
@max-itzpapalotl
max-itzpapalotl / reqwestclient.md
Last active February 25, 2024 14:45
25. An HTTP client with the crate

25. An HTTP client with the reqwest crate

In this video I show you how to do HTTP requests with the reqwest crate. I will use the server programs from the previous video 24. as server for this video.

Sending a simple HTTP GET request

We use the reqwest crate as well as the tokio asynchronous runtime:

@max-itzpapalotl
max-itzpapalotl / warpexample.md
Last active February 25, 2024 14:43
24. An HTTP server using warp I

24. An HTTP server using warp I

In this video I show how to set up an HTTP server with the warp crate.

Our first GET route

We need the following dependencies in Cargo.toml (we might not need all listed features):

@max-itzpapalotl
max-itzpapalotl / markertraits.md
Last active February 25, 2024 14:44
23. The marker traits Copy, Clone, Send and Sync

23. The marker traits Copy, Clone, Send and Sync

Copy

#[derive(Debug)]
struct Point {
    pub x: u32,
    pub y: u32,
}
@max-itzpapalotl
max-itzpapalotl / smartp.md
Last active February 18, 2024 22:21
22. Smart pointers

22. Smart pointers

Box

This is just a unique pointer, cannot be cloned, single threaded.

#[derive(Debug)]
struct Person {
    pub name: String,
@max-itzpapalotl
max-itzpapalotl / asynctokio.md
Last active February 11, 2024 17:06
21. Async functions and tokio

21. Async functions and tokio

In this video I explain how to use async functions, a bit how they work and how to use a runtime from the tokio crate.

Our first async function

We are using the futures crate:

@max-itzpapalotl
max-itzpapalotl / matching.md
Last active February 25, 2024 14:46
20. Matching

20. Matching

In this video I give an overview over the matching capabilities in Rust.

Types of patterns

#[derive(Debug)]
enum X {
    A,
@max-itzpapalotl
max-itzpapalotl / environment.md
Last active February 25, 2024 14:46
19. Environment and paths

19. Environment (command line args, env vars, paths, exit code)

In this video I give a guided tour over features dealing with the environment of a process.

Command line arguments and environment variables

use std::env;
use std::collections::HashMap;
@max-itzpapalotl
max-itzpapalotl / json.md
Last active January 26, 2024 19:29
18. JSON and serde

18. JSON and serde

Rust has excellent serialization and deserialization support via the serde crate: https://docs.rs/serde/latest/serde/

For the examples in this video we need the following in Cargo.toml:

[dependencies]
serde = { version = "1.0.195", features = ["derive"] }
@max-itzpapalotl
max-itzpapalotl / files.md
Last active February 25, 2024 14:46
17. File I/O

17. File I/O

Low level unbuffered I/O

The fs module is for file system access and has the File struct, the io module contains traits and code for performing I/O, the most fundamental ones are the Read and Write and Seek traits.

use std::fs;