[−][src]Module show_notes::e002
Something borrowed, something... moved?
- Date: October 12, 2015
- Subject: The
struct
data type constructor, and the basics of Rust's "ownership" concept and "borrowing" and "moving". - Audio
Notes
Today's episode discusses, and the associated source code demonstrates, a few basic behaviors of structs... including borrowing!
After taking a short look at one of Rust's basic approaches to creating new
types, we dive into a fairly thorough overview of how borrowing works in
fairly run-of-the-mill Rust code. This is a basic introduction, and as such
I'm not getting into things like heap-allocated memory (Box
) or dealing
with move
semantics with threads or closures. (I haven't actually figured
those out well enough yet to write something like this for them!)
As usual, you'll want to have the src
open to see what I'm doing with
the components documented below.
Links
rustfmt
-- a tool for formatting Rust code- RFC for incremental compilation
Follow/Support
- New Rustacean:
- Twitter: @newrustacean
- App.net: @newrustacean
- Patreon
- Email: [email protected]
- Twitter: @newrustacean
- Chris Krycho
- Twitter: @chriskrycho
- App.net: @chriskrycho
- Twitter: @chriskrycho
Structs
Circle | This struct is simple but useful to see how borrowing and moving work. |
Functions
borrow | Demonstrates general borrowing of an immutable reference. |
borrow_mut | Demonstrates general borrowing of a mutable reference. |
demonstrate_method_ownership | Demonstrates how the same concepts apply when dealing with methods. |
demonstrate_ownership | Demonstrates how borrowing works with plain old functions. |
move_circle | Demonstrates general moving of an instance. |