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 / traits.md
Last active January 16, 2024 22:33
16. Traits

16. Traits

In this episode we present traits. They are used to define interfaces, which is useful for type-checked template code and for dynamic dispatch. In this way, traits are similar to inheritance in C++ as well as to concepts.

First example: Type-safe template code

@max-itzpapalotl
max-itzpapalotl / stringmanip.md
Last active January 14, 2024 21:31
15. String manipulation

15. String manipulation

Converting to strings

fn main() {
    let b = b"abc\xc3\xa4\xc3\xb6\xc3\xbc";
    let s = std::str::from_utf8(&b[0..9]);
    println!("Result: {:?}", s);
}
@max-itzpapalotl
max-itzpapalotl / rust-analyzer.md
Last active January 14, 2024 12:58
14. `rust-analyzer`

14. The language server rust-analyzer

This video is different from others. We look at a small project and see what the combination of rust-analyzer (language server) and vim with CoC can do for you.

The project

The Cargo.toml looks like this:

@max-itzpapalotl
max-itzpapalotl / cargo.md
Last active January 12, 2024 11:21
13. Cargo

13. Cargo

Cargo is the package manager, everybody uses it.

Basic setup for a single executable

cargo new project
@max-itzpapalotl
max-itzpapalotl / formatting.md
Last active January 11, 2024 19:46
12. Formatting

12. Formatting

format! and print!

fn main() {
    let s = format!("{}", 12u32);            // Integers
    println!("{}", s);                       // Strings
    println!("{}", 123.456f64);              // Floats
    println!("{}", "abc");                   // String slices
@max-itzpapalotl
max-itzpapalotl / modules.md
Last active January 11, 2024 18:54
11. Modules

11. Modules

Defining Modules and visibility

mod a {
    fn g() {
        println!("g");
    }
 pub fn f() {
@max-itzpapalotl
max-itzpapalotl / control_structures.md
Last active January 10, 2024 06:53
10. Control Structures

10. Control Structures

if statements and expressions

fn main() {
    let args : Vec<String> = std::env::args().collect();
    if args.len() > 1 {
        println!("First argument: {}", args[1]);
    } else {
@max-itzpapalotl
max-itzpapalotl / overview.md
Last active March 17, 2024 22:03
"Rust = Future<C++>" overview

Rust = Future<C++>

In this channel I introduce Rust for people who know C++ already. The videos are supposed to be short and cover only a single topic. Each video comes with a github gist, which contains all the code and commands for copy/paste, such that you can easily try out things. Furthermore, there are links to the excellent Rust documentation.

This is still work in progress. As you can see in the table below,

@max-itzpapalotl
max-itzpapalotl / enums.md
Last active January 8, 2024 17:43
9. Enums, algebraic types and matching

9. Enums, algebraic types and matching

  • Simple enums, construction, handling
  • Enums as tagged variants, construction, handling
  • Enum arguments
  • Matching and destruction
  • Methods for enums

Simple enums

@max-itzpapalotl
max-itzpapalotl / hashmaps.md
Last active January 7, 2024 12:35
8. HashMaps

8. HashMaps

  • Construction, insertion
  • Lookup, deletion
  • Matching
  • HashMap literals

Construction, insertion