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

画像メーカー品番商品概要入手可能な数量料金詳細を表示
RASPBERRY PI PICO 2 RP2350SC1631RASPBERRY PI PICO 2 RP235025969 - 即時$829.00詳細を表示
RASPBERRY PI PICO 2 H RP2350SC1632RASPBERRY PI PICO 2 H RP23502614 - 即時$995.00詳細を表示
RASPBERRY PI PICO 2 W RP2350SC1633RASPBERRY PI PICO 2 W RP23505961 - 即時$1,161.00詳細を表示
RASPBERRY PI PICO 2 WH RP2350SC1634RASPBERRY PI PICO 2 WH RP23502195 - 即時$1,327.00詳細を表示
RES 220 OHM 5% 1/4W AXIALCF14JT220RRES 220 OHM 5% 1/4W AXIAL109124 - 即時
30000 - 工場在庫品
$17.00詳細を表示
LED RED CLEAR T-1 3/4 T/HLTL-4224LED RED CLEAR T-1 3/4 T/H72310 - 即時$23.00詳細を表示
TMP102 DIGITAL TEMP SENSOR BOARD13314TMP102 DIGITAL TEMP SENSOR BOARD248 - 即時$987.00詳細を表示
USB AM TO USB MICRO, USB 2.0 - 1DH-20M50055USB AM TO USB MICRO, USB 2.0 - 110945 - 即時$257.00詳細を表示
JUMPER WIRE M TO M 6" 28AWG1957JUMPER WIRE M TO M 6" 28AWG3608 - 即時$323.00詳細を表示
BREADBRD TERM STRIP 3.20X2.00"FIT0096BREADBRD TERM STRIP 3.20X2.00"3452 - 即時$481.00詳細を表示
SWITCH TACTILE SPST-NO 0.05A 24V1825910-6SWITCH TACTILE SPST-NO 0.05A 24V42542 - 即時$22.00詳細を表示