Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. Box<dyn Trait> is a syntax sugar for Box<dyn Trait + 'static>. If the trait inside Box does not have a static life time, you have to specify it manually, e.g., Box<dyn Trait + 'some_life_time>.

  2. You can leak a memory to make it has a static life time using Box::leak.

5
b = 5
5

Use Box to Construct Recursive Types

enum List {
^^^^^^^^^ recursive type has infinite size
    Cons(i32, List),
              ^^^^ recursive without indirection
recursive type `List` has infinite size
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable

Box<
Cons(1, Cons(2, Cons(3, Nil)))
1
()