77
Announcing Rust 1.84.1 (blog.rust-lang.org)
submitted 6 months ago by neme@lemm.ee to c/rust@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] Ephera@lemmy.ml 9 points 6 months ago

In a struct, you typically want only owned data types. If you're passing something as a parameter to a function, you typically want only references.

In a sense, that pushes your program to be very tree-shaped. Your data is initialized and held at the root of the tree (or a sub-tree) and only temporarily passed down as a reference.

In my experience, following this rule gets you there for 80% of programs. Only really more complex programs or libraries may need to deal with lifetimes and the various cop-out mechanisms.
If you're hurting your brain, that's probably because you're experienced in other languages and have design patterns in mind that don't work with this model.

this post was submitted on 31 Jan 2025
77 points (98.7% liked)

Rust

7232 readers
17 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS