Rust Container Cheat Sheet
Box<T> ptr T where T: Sized Vec<T> ptr cap len T T T len cap Note: String = Vec<u8> Box<[T]> ptr len T T T T len Note: &str = &[u8] &T ptr len T T T T T &T ptr T where T: Sized &Trait data vtable &Trait data vtable destructor size align method1 method2 Rc<T> ptr strong weak T Arc<T> ptr strong weak T Mutex<T> inner poison T mutex Consider using parking_lot, which doesn't allocate a raw mutex Cell<T> T RefCell<T> borrow T enum (A, B, C) or tag A or tag B or tag C Also basic of Result, Cow, etc. Option<T> tag T or T when T contains pointers which can be null Legend ptr 4/8 bytes size 4/8 bytes atomic 4/8 bytes fn 4/8 bytes heap allocation, implies ownership T user defined type defer Rust container cheat sheet, by Raph Levien, Copyright 2017 Google Inc., released under Creative Commons BY, 2017-04-21, version 0.2
A detailed diagram explains how Rust containers and smart pointers are laid out in memory, including Box, Vec, strings, references, Rc, Arc, Mutex, Cell, RefCell, enums, Result, Cow, and Option. The joke is that an extremely technical cheat sheet is presented as a meme, useful as a reaction for Rust programmers discussing ownership, allocation, memory layout, or confusing type internals. EN: A detailed diagram explains how Rust containers and smart pointers are laid out in memory, including Box, Vec, strings, references, Rc, Arc, Mutex, Cell, RefCell, enums, Result, Cow, and Option. The joke is that an extremely technical cheat sheet is presented as a meme, useful as a reaction for Rust programmers discussing ownership, allocation, memory layout, or confusing type internals.
- @profunctor_io / 2116 2019-04-26
- Type
- image
- Size
- 800×447 · 53.9 KiB
- Mood
- технический, абсурдный
- Language
- en
- Added