Skip to content
e027: Trust Me; I Promise! episode artwork

Dec 1, 2018 21 min

e027: Trust Me; I Promise!

from New Rustacean

An intro to unsafe Rust and Rust’s idea of safety. Show Notes Errata A quick correction: on the show I said that a trait needed to be unsafe when it had an unsafe fn method. This isn’t correct: safe traits can have unsafe methods, and unsafe traits can exist without any methods at all (as implied by my reference to Send and Sync). You can see this in practice in the following example, which compiles just fine! trait ASafeTrait { unsafe fn unsafe_method() {} } unsafe AnUnsafeTrait {} The idea of an unsafe trait is that it has some conditions which you must uphold to safely implement it – again, just as with Send and Sync. In the case of most traits, this will be because some trait method has invariants it needs to hold else it would cause undefined behavior. For another example of this, see the (unstable as of the time of recording) trait std::iter::TrustedLen. Thanks to Rust language team member @centril for noting this to me after listening when I was recording the show live! Links The Rust Programming Language, Chapter 19: Unsafe The Nomicon “Rust and OpenGL from Scratch”, by Nerijus Arlauskas Examples Borrow-checked code in unsafe let mut f = String::from("foo"); unsafe { let borrowed = &mut f; let borrow_again = &f; println!("{}", borrowed); // This would be unsafe and throw an error: // println!("{}", borrow_again); } (See it in a playground) Safely mutating a raw pointer let f = Box::new(12); let mut g = Box::into_raw(f); g = &mut (g + 10); (See it in a playground) Sponsors Thanks to Parity for sponsoring the show again. Go check out their Rust jobs! Patreon Sponsors Adam Green Aleksey Pirogov Alexander Payne Alexander Kryvomaz Andrew Thompson Anthony Deschamps Anthony Scotti Behnam Esfahbod Benjamin Wasty Brandon ‘Spanky’ Mills Brian Casiello Brian Manning Brian McCallister Bryan Stitt Bryce Johnston Caryn Finkelman Cass Costello Chap Lovejoy Charlie Egan Chip Chris Palmer Daniel Dan Abrams Daniel Bross Daniel Collin Daniel Mason David Hewson Derek Morr Doug Reeves Eugene Bulkin Fábio Botelho Gaveen Prabhasara Graham Wihlidal Henri Sivonen Ian Jones “Jake”“ferris”" Taylor" Jako Danar James Cooper James Hagans II Jerome Froelich John Rudnick Jon Jonathan Knapp Jonathan Turner Joseph Hain Joseph Marhee Justin Ossevoort Kai Yao Keith Gray Kilian Rault Lee Jenkins Luca Schmid Luiz Irber Lukas Eller Martin Heuschober Masashi Fujita Matt Rudder Matthew Brenner Matthias Ruszala Max Jacobson Max R.R. Collada Messense Lv Micael Bergeron Michael Mc Donnell Michael Sanders Nathan Sculli Nick Coish Nick Gideo Nick Stevens Nicolas Pochet Olaf Leidinger Oliver Uvman Oluseyi Sonaiya Ovidiu Curcan Pascal Patrick O’Doherty Paul Naranja Paul Osborne Peter Scholtens Peter Tillemans Ralph Giles Ramon Buckland Randy MacLeod Raph Levien Richard Dallaway Rob Tsuk Robert Chrzanowski Ryan Blecher Ryan Osial Scott Moeller Sebastián Ramírez Magrí Simon Dickson Simon G Steffen Loen Sunde Steve Jenson Steven Knight Steven Murawski Stuart Hinson Tim Brooks Tim Süberkrüb Tom Prince Toolmaker’s Guild Ty Overby Tyler Harper Victor Kruger Will Greenberg William Roe Zak van der Merwe Zachary Snyder Zaki (Thanks to the couple people donating who opted out of the reward tier, as well. You know who you are!) Become a sponsor Patreon Venmo Dwolla Cash.me Flattr PayPal.me Contact New Rustacean: + Twitter: @newrustacean + Email: [email protected] Chris Krycho + GitHub: chriskrycho + Twitter: @chriskrycho

Episode details come from the podcast's RSS feed.

Embed this episode

Ready to play

e027: Trust Me; I Promise!

0:00 21:27

No transcript yet.

Requests help us decide what to transcribe next.

The Course Mentors Podcast The Course Mentors Hey there, future course creator! Ever feel like turning your know-how into an online course is like trying to solve a Rubik's cube blindfolded? Well, grab your headphones because "The Course Mentors Podcast" is here to be your secret weapon! Meet Aimee and Odette (that's us!), your new best friends in the course creation world. We've been in the trenches for over a decade, and for the last five years, we've been rocking the online course space. Now we're here to spill all our secrets in bite-sized, 15-20 minute episodes that'll fit perfectly in your coffee breaks. No fluff, no filler - just real, actionable advice that'll take you from "um, what's a landing page?" to "holy moly, I just hit six figures!". We're talking everything from crafting your course to marketing it like a pro and building a business that'll have you pinching yourself. Whether you're dreaming of ditching the 9-to-5 grind, adding a sweet extra income str CISO Perspectives (public) N2K Networks This season on CISO Perspectives, host Kim Jones explores some of the challenges of leading through uncertainty. We explore the complexity of the changing nature of regulation and working with the federal government, the evolution of privacy and fraud, and how emerging technologies like AI and quantum computing are changing cyber. When you don’t know what questions to ask, you’re afraid to ask, or don’t know who to ask, CISO Perspectives provides the foundation for learning in this brave new world. The 48 Laws of Power by Robert Greene (Full Audiobook) Robert Greene Amoral, cunning, ruthless, and instructive, this multi-million-copy New York Times bestseller is the definitive manual for anyone interested in gaining, observing, or defending against ultimate control – from the author of The Laws of Human Nature.In the book that People magazine proclaimed “beguiling” and “fascinating,” Robert Greene and Joost Elffers have distilled three thousand years of the history of power into 48 essential laws by drawing from the philosophies of Machiavelli, Sun Tzu, and Carl Von Clausewitz and also from the lives of figures ranging from Henry Kissinger to P.T. Barnum.Some laws teach the need for prudence (“Law 1: Never Outshine the Master”), others teach the value of confidence (“Law 28: Enter Action with Boldness”), and many recommend absolute self-preservation (“Law 15: Crush Your Enemy Totally”). Every law, though, has one thing in common: an interest in t

Frequently asked questions

How long is this episode of New Rustacean?

This episode is 21 minutes long.

When was this New Rustacean episode published?

This episode was published on December 1, 2018.

Can I download this New Rustacean episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.