Free YouTube views likes and subscribers? Easily!
Get Free YouTube Subscribers, Views and Likes

Choose the Right Option

Follow
Logan Smith

"ReferencetoOption" and "Optionalreference"* are both ways to represent "a reference to a value that may or may not be there" in Rust. So which one should you use in your APIs? Hear me spoil my answer within the first 10 seconds, and then stick around to get real nerdy about a topic you may have never spent 15+ minutes thinking about before. Featuring special guest appearances from memory layout visualizations (feat. niche optimizations), the venerable ToOwned trait, and me saying the word "Data" several hundred times.

And yes, I do in fact regret missing the opportunity to make a Sum 41 reference during the memory layout visualization.

Option docs https://doc.rustlang.org/std/option/...
ToOwned docs https://doc.rustlang.org/std/borrow/...
Niche optimization / "null pointer optimization" (which IS guaranteed for OptionrefT) https://doc.rustlang.org/std/option/...

I use the amazing Manim library for animating these videos, and I edit them with Blender and Audacity.
https://www.manim.community/
https://www.blender.org/
https://www.audacityteam.org/

*YouTube doesn't allow angle brackets in video descriptions.

posted by electryas