1 of 1

ptr

T

Legend

4/8 bytes (usize)

Box<T>

Vec<T>

len

cap

ptr

cap

len

4/8 bytes

T

T

T

Rc<T>

ptr

strong

weak

T

Box<[T]>

len

ptr

len

T

T

T

Box<dyn Trait>

T

vtable

Arc<T>

ptr

strong

weak

T

4/8 bytes

allocation

T

user defined type

borrow

T

Cell<T>

T

poison

T

mutex

data

size

align

method1

method2

len

ptr

len

T

T

T

&dyn Trait

T

vtable

data

T

T

4/8 bytes

enum {A, B, C}

tag

when T contains pointers which can't be null

ptr

T

&T

Note: String has same memory layout as Vec<u8>

Note: &str has same memory layout as &[u8]

Rust container cheat sheet, by Raph Levien, Copyright 2017 Google Inc., released under Creative Commons BY, 2017-04-21, version 0.0.4

Also basis of Result, Cow, etc.

where T: Sized

heap allocation,

implies ownership

where T: Sized

T

T

Consider using parking_lot, which�doesn’t allocate the raw mutex

tag

or

or

tag

A

B

or

tag

C

or

tag

inner