Rust: Store Data on the Heap with Box
The Dev Method
View ChannelAbout
No channel description available.
Video Description
#rust #smart #box ! At 1:08, I said "Defer Trait", but I actually mean "Deref Trait" Box is a straightforward example of one Smart Pointer in Rust. Box allows you to store data on the heap instead of the stack. Instead of passing around your data, and copying it’s total memory on the stack, you can use a Box to store the data and avoid the memory copies on the stack and defer to pointer copies on the stack. This is the single responsibility of the Box. Box is a smart pointer because it implements the `Defer trait` which allows the `T` to be treated like references. If you are unfamiliar with the concept of stack vs. heap, please refer to The Rust Programming Book chapter 4. 0:00 intro 2:05 Using Box to Store Data on the Heap 3:11 Enabling Recursive Types with Boxes 5:55 Computing the Size of a Non-Recursive Type 8:10 Using Box to Get a Recursive Type with a Known Size Links Learn more about traits https://doc.rust-lang.org/book/ch17-02-trait-objects.html Box documentation https://doc.rust-lang.org/std/boxed/index.html
You May Also Like
Upgrade Your iPhone Experience
AI-recommended products based on this video

for Magsafe Car Mount【20 Strong Magnets 】Magnetic Phone Holder for Car Phone Holder Mount Dash【360°】Cell Phone Mount for Car Accessories,Car Mount for iPhone 16 Pro Max 15 14 13 12 Plus MagSafe Cases

Apple AirPods Pro 2 Wireless Earbuds, Bluetooth Headphones, Active Noise Cancellation, Transparency, Personalized Spatial Audio, High-Fidelity Sound, H2 Chip, USB-C Charging

3 in 1 Charging Station for iPhone, Wireless Charger for iPhone 16 15 14 13 12 11 X Pro Max & Apple Watch - Charging Stand Dock for AirPods Global Recycled Standard

3 in 1 Charging Station for iPhone, Wireless Charger for iPhone 16 15 14 13 12 11 X Pro Max & Apple Watch - Charging Stand Dock for AirPods (Blue) Global Recycled Standard

Wireless Charger for iPhone- 3 in 1 Charging Station for iPhone 16/15/14/13/12/Pro Max/Pro/Mini/Plus, Apple Watch 10/9/8/7/SE/6/5/4/3/2/1/Ultra2/Ultra, AirPods pro/2/3/4

OHLPRO Tablet Holder for Car, iPad Holder for Car Air Vent Mount, Universal Dashboard Windshield 2-in-1 Cradle TPU Suction Sticky Gel for iPad/iPad mini Samsung Galaxy Size 6"- 10.5" iPad Car Holder

Magnetic Car Mount Air Vent Cell Phone Holder, Universal Vehicle Dash Dashboard Ac Airvent Cellphone Magic Stand with Clip Hook, for iPhone 16 15 Samsung Lenovo Google etc

AINOPE Phone Holder for Car Vent 2025 Gravity Air Vent Car Phone Holder Mount for iPhone 16 Pro Max with Vent Clip Hand Free Cell Phone Car Mount for iPhone 16 Plus Samsung S25 Ultra Car Accesorries
![Miracase Car Phone Mount, [2025 Upgraded Strong Military Grade Suction Cup] Long Arm Phone Holder for Car Dashboard Windshield Vent, Hands Free Cell Phone Holder Compatible with All Mobile Phones Global Recycled Standard](https://m.media-amazon.com/images/I/81oehGW5OLL._AC_UL960_FMwebp_QL65_.jpg)
Miracase Car Phone Mount, [2025 Upgraded Strong Military Grade Suction Cup] Long Arm Phone Holder for Car Dashboard Windshield Vent, Hands Free Cell Phone Holder Compatible with All Mobile Phones Global Recycled Standard
![Spigen Case for Galaxy S25 Case, Rugged Armor MagFit [Fast Wireless Charging] Compatible with MagSafe - Black](https://m.media-amazon.com/images/I/81osE87mFrL._AC_UL960_FMwebp_QL65_.jpg)
Spigen Case for Galaxy S25 Case, Rugged Armor MagFit [Fast Wireless Charging] Compatible with MagSafe - Black
![Vihibii for Samsung Galaxy S25+ Plus Wallet Case with Card Holder (4 Cards) [RFID Blocking] & Slide Camera Cover & Raised Edges Protect Screen, Shockproof Rugged Case for S25+ Plus 6.7" 2025, Black](https://m.media-amazon.com/images/I/71YSDNV+PHL._AC_UL960_FMwebp_QL65_.jpg)
Vihibii for Samsung Galaxy S25+ Plus Wallet Case with Card Holder (4 Cards) [RFID Blocking] & Slide Camera Cover & Raised Edges Protect Screen, Shockproof Rugged Case for S25+ Plus 6.7" 2025, Black
![Vihibii for Samsung Galaxy S25+ Plus Wallet Case with Card Holder (4 Cards) [RFID Blocking] & Slide Camera Cover & Raised Edges Protection, Shockproof Rugged Case for S25+ Plus 6.7" 2025, Hot Pink](https://m.media-amazon.com/images/I/71K-GtDw48L._AC_UL960_FMwebp_QL65_.jpg)
Vihibii for Samsung Galaxy S25+ Plus Wallet Case with Card Holder (4 Cards) [RFID Blocking] & Slide Camera Cover & Raised Edges Protection, Shockproof Rugged Case for S25+ Plus 6.7" 2025, Hot Pink
![Spigen Case for iPhone 16 Pro Max Case, Rugged Armor [MagFit] Compatible with MagSafe - Matte Black](https://m.media-amazon.com/images/I/71Gh0VOQtlL._AC_UL960_FMwebp_QL65_.jpg)
Spigen Case for iPhone 16 Pro Max Case, Rugged Armor [MagFit] Compatible with MagSafe - Matte Black
![Spigen Spigen Tempered Glass Screen Protector [GlasTR EZ FIT] designed for Nintendo Switch 2 (2025) - 2 Pack](https://m.media-amazon.com/images/I/61L0hIGSbYL._AC_UL1500_FMwebp_QL65_.jpg)
Spigen Spigen Tempered Glass Screen Protector [GlasTR EZ FIT] designed for Nintendo Switch 2 (2025) - 2 Pack
![Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)](https://m.media-amazon.com/images/I/71N7xhCJnoL._AC_UL960_FMwebp_QL65_.jpg)
Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)

Anker 332 USB-C Hub (5-in-1) with 4K HDMI Display, 5Gbps - and 2 5Gbps USB-A Data Ports and for MacBook Pro, MacBook Air, Dell XPS, Lenovo Thinkpad, HP Laptops and More

AsperX for Magsafe Power Bank, 10000mAh Wireless Magnetic Power Bank, 22.5W Wire Fast Charging Portable Charger with USB C Cable, LCD Display for Magsafe Battery Pack for iPhone 16/15/14/13/12

eazpower for Magsafe Power Bank 10000mAh, Magnetic Battery Pack Wireless, 20W PD Fast Charging, Compact Portable Charger with Built-in Cables and Stand for iPhone 16/15/14/13/12/ Apple Watch/Airpods

INIU 45W Power Bank, Ultra Small 10000mAh Portable Charger, USB C in&Out Fast Charging Battery Pack, Travel External Phone Powerbank Compatible with iPhone 16 15 Samsung S25 S24 Google Pixel iPad etc

iWALK Magnetic Power Bank for iPhone, 10000mAh Qi2 15W Wireless Power Bank, 30W Powerbank Fast Charging with USB-C Cable, Portable Charger with LED Display for iPhone 16/15/14/13, Android, Black Recycled Claim Standard Blended
![VANMASS [85+LBS Strongest Suction & Clip] 2025 Upgrade Car Phone Holder [Patent & Safety Certs] Cell Phone Mount Truck Stand for Dashboard Windshield Vent for iPhone 16 Pro Max 15 14 13 12 Samsung](https://m.media-amazon.com/images/I/71bHSP1cRkL._AC_UL960_FMwebp_QL65_.jpg)
VANMASS [85+LBS Strongest Suction & Clip] 2025 Upgrade Car Phone Holder [Patent & Safety Certs] Cell Phone Mount Truck Stand for Dashboard Windshield Vent for iPhone 16 Pro Max 15 14 13 12 Samsung
![iPhone Charger Fast Charging [Apple MFi Certified] USB C to Lightning Cable 6FT USBC to Lightning Cable Nylon Braided Type C Cord for iPhone 14 13 12 11 Pro Max XR XS X 8 7 6 Plus SE, iPad](https://m.media-amazon.com/images/I/517jTqwo1nL._AC_UL960_FMwebp_QL65_.jpg)
iPhone Charger Fast Charging [Apple MFi Certified] USB C to Lightning Cable 6FT USBC to Lightning Cable Nylon Braided Type C Cord for iPhone 14 13 12 11 Pro Max XR XS X 8 7 6 Plus SE, iPad
![iPhone Charger [Apple MFi Certified] 3FT, 3Pack USB A to Lightning Cable Braided Fast Charging Apple Cord Compatible with iPhone 14 13 12 11 Pro Max XS XR X 8 7 6 5 Plus iPad/iPod/AirPods](https://m.media-amazon.com/images/I/71xZOlUELbL._AC_UL960_FMwebp_QL65_.jpg)
iPhone Charger [Apple MFi Certified] 3FT, 3Pack USB A to Lightning Cable Braided Fast Charging Apple Cord Compatible with iPhone 14 13 12 11 Pro Max XS XR X 8 7 6 5 Plus iPad/iPod/AirPods






















![Visualizing memory layout of Rust's data types [See description/first comment]](https://imgz.pc97.com/?width=500&fit=cover&image=https://i.ytimg.com/vi/rDoqT-a6UFg/hqdefault.jpg)