• Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    39
    ·
    1 day ago

    The rule of thumb I always tell people is that they should generally put owned data into struct fields and references into function parameters.

    • calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      14
      ·
      1 day ago

      Good rule of thumb. As long as it’s not followed blindly of course.

      Structs with lifetimes are often quite convenient. Especially for performance.

    • harrowhawk@lemmy.sdf.org
      link
      fedilink
      arrow-up
      8
      arrow-down
      3
      ·
      1 day ago

      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.