0% found this document useful (0 votes)
126 views1 page

Cheat Sheet PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views1 page

Cheat Sheet PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

into_boxed_slice

Box<T> Vec<T> Box<[T]> Box<Trait> &Trait


ptr ptr cap len ptr len data vtable data vtable Legend
T T T T T T T T T ptr 4/8 bytes

where T: Sized
len len size 4/8 bytes
cap into_vec
Note: String has same destructor atomic 4/8 bytes
memory layout as Vec<u8>
&T &[T] size
align fn 4/8 bytes
ptr ptr len
method1
method2 heap allocation,
T T T T T T allocation
implies ownership
where T: Sized
len
Note: &str has same
T user defined type
memory layout as &[u8]
enum {A, B, C} deref
Rc<T> Arc<T> Mutex<T>
ptr ptr inner poison T tag A
or
tag B
or
strong weak T strong weak T mutex tag C
Also basis of Result, Cow, etc.
Consider using parking_lot, which
doesn’t allocate the raw mutex
Option<T> Option<T>
tag T T
Cell<T> RefCell<T> or or
T borrow T tag
when T contains pointers
which can't be null

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

You might also like