VideoLibrary

Intro to Embedded Rust Part 4: Ownership and Borrowing | DigiKey

Rust's ownership and borrowing system can be confusing at first. In this video, we break down the seven fundamental rules that govern how Rust manages memory safely without a garbage collector or runtime overhead. To keep it applicable to embedded systems, we use a stack-based example (rather than relying on the heap examples found in the Rust Book). You'll learn how ownership transfers work, when values are dropped from memory, and how references provide safe access to data without the memory bugs that plague C and C++ programs. No hardware required for this episode: just your computer and the Rust compiler to explore these concepts through hands-on code examples. The written guide for this episode can be found here: https://www.digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-4-ownership-and-borrowing The GitHub repository containing the Docker image and example code for this series can be found here: https://github.com/ShawnHymel/introduction-to-embedded-rust This tutorial provides an in-depth exploration of Rust's memory management rules, covering each principle with clear examples and explanations. We start with basic ownership: how each value has exactly one owner and what happens when ownership is transferred (moved) between variables. You'll understand the difference between types that implement the Copy trait (like primitive integers and arrays) versus types that use move semantics. We explore scoping rules and how Rust automatically deallocates memory when owners go out of scope, eliminating memory leaks without manual cleanup. We then dive into borrowing and references, explaining the crucial rule that you can have either multiple immutable references or one mutable reference at a time. We also look at why references must always be valid, preventing dangling pointer bugs that cause crashes and security vulnerabilities in other languages. We demonstrate partial moves with compound types like tuples and structs, showing what happens when you move ownership of only part of a value. We conclude with slice operations, including how to create multiple mutable slices to non-overlapping array regions using split_at_mut() (a useful pattern for working with buffers in embedded systems). Unlike typical Rust tutorials that rely heavily on heap-allocated types (like String and Vec), our examples use stack-only data structures that mirror real embedded development constraints, making this tutorial especially relevant for bare-metal programming. These ownership and borrowing rules are what make Rust unique among systems programming languages, offering the performance of C with memory safety guarantees typically found only in garbage-collected languages.

2/10/2026 4:14:40 PM

Part List

ImageManufacturer Part NumberDescriptionAvailable QuantityPriceView Details
RASPBERRY PI PICO 2 RP2350SC1631RASPBERRY PI PICO 2 RP235025971 - Immediate$4.30View Details
RASPBERRY PI PICO 2 H RP2350SC1632RASPBERRY PI PICO 2 H RP23502754 - Immediate$5.16View Details
RASPBERRY PI PICO 2 W RP2350SC1633RASPBERRY PI PICO 2 W RP23505965 - Immediate$6.02View Details
RASPBERRY PI PICO 2 WH RP2350SC1634RASPBERRY PI PICO 2 WH RP23502210 - Immediate$6.88View Details
RES 220 OHM 5% 1/4W AXIALCF14JT220RRES 220 OHM 5% 1/4W AXIAL109274 - Immediate
30000 - Factory Stock
$0.09View Details
LED RED CLEAR T-1 3/4 T/HLTL-4224LED RED CLEAR T-1 3/4 T/H72310 - Immediate$0.12View Details
TMP102 DIGITAL TEMP SENSOR BOARD13314TMP102 DIGITAL TEMP SENSOR BOARD248 - Immediate$5.12View Details
USB AM TO USB MICRO, USB 2.0 - 1DH-20M50055USB AM TO USB MICRO, USB 2.0 - 110945 - Immediate$1.33View Details
JUMPER WIRE M TO M 6" 28AWG1957JUMPER WIRE M TO M 6" 28AWG3608 - Immediate$1.68View Details
BREADBRD TERM STRIP 3.20X2.00"FIT0096BREADBRD TERM STRIP 3.20X2.00"3452 - Immediate$2.50View Details
SWITCH TACTILE SPST-NO 0.05A 24V1825910-6SWITCH TACTILE SPST-NO 0.05A 24V42577 - Immediate$0.11View Details