When returning an immutable reference to a private struct field. (On mobile and used vertical bars instead of a bunch of HTML codes)

  • RunAwayFrog@sh.itjust.works
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    Note: the ᐸᐳ characters used below are Canadian Aboriginal syllabics because Lemmy devs haven’t fixed broken input sanitization yet.


    Well, getters are not an official concept in Rust. You can do whatever works best in your case.

    Just worth pointing out that a method with a return value of OptionVecStringᐳᐳ wouldn’t be really a getter, as you must be constructing values, or moving ownership, or cloning. None of these actions conceptually belong to a getter.

    Also, you should be clear on the what the Option abstraction means. Does it mean the vector is empty? Does it mean the vector does not exist or some sort of null (FFI ore serialization contexts)? And make sure the code does what you expect it to do.