Skip to content

Instantly share code, notes, and snippets.

View haifenghuang's full-sized avatar

HuangHaiFeng haifenghuang

View GitHub Profile
@haifenghuang
haifenghuang / magic.md
Created January 29, 2024 06:19 — forked from DarinM223/magic.md
C++ magical template examples:

Generic constraints

In Rust it is easy to constrain a generic type to only include types extending from some interface. For example:

pub trait DoSomething {
    fn do_something(&self);
}
@haifenghuang
haifenghuang / Concepts.md
Created January 29, 2024 05:25 — forked from DarinM223/Concepts.md
Rust concept explanations

My explanation of the main concepts in Rust

There are three main concepts with Rust:

  1. Ownership (only one variable "owns" the data at one time, and the owner is in charge of deallocating)
  2. Borrowing (you can borrow a reference to an owned variable)
  3. Lifetimes (all data keeps track of when it will be destroyed)

These are fairly simple concepts, but they are often counter-intuitive to concepts in other languages, so I wanted to give a shot at