this post was submitted on 25 Mar 2022
11 points (100.0% liked)

Rust Programming

8335 readers
2 users here now

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 2 years ago

If you place data in a struct, you usually want that to be owned by that struct, so you usually don't want to store a reference in a struct.

If you pass data around as parameters, you usually do want to pass those by reference, except for simple data types, i.e. anything that is itself smaller or the same size as a pointer.
For example, on a 64-bit system pointers have a size of 64 bits, so u8, u16, u32, u64, i8 etc. can all be passed around by value (they'll automatically get copied).