Post #2584652
2026-01-31 20:38 UTC
The rule of thumb I always tell people is that they should generally put owned data into struct fields and references into function parameters.
Replies (3)
-
@calcopiritus@lemmy.world 2026-01-31 21:04
Good rule of thumb. As long as it's not followed blindly of course. Structs with lifetimes are often quite convenient. Especially for performance.
-
@joyjoy@lemmy.zip 2026-01-31 23:21
I recently learned you can pass a `&String` to a `&str` parameter, so that's neat.
-
@harrowhawk@lemmy.sdf.org 2026-01-31 20:43
I like this rule of thumb and it goes nicely with the “if you have more than 3 arguments to a function, consider making a struct to pass the arguments in” rule of thumb because You can have the struct use a named lifetime (or several) for the different parameters so it doesn’t own them! Best of both worlds.