• Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    7
    ·
    1 month ago

    Rule of thumb, which I feel gets you 80% there:

    If you store data in a struct, you want that struct to have ownership of that data. So, avoid storing references in structs.
    If you need to pass data into a function, you usually want to pass it as a reference.

    This makes it so you have your data stored in some place with the ownership and from there you just pass data down into functions as references. It forces you to structure your program like a tree (which is often a very good idea to begin with).