Ephera,

Hmm, interesting. The documentation tells me, it creates a new Option value, and allocating memory every time someone just wants to look at a value could be pretty bad.

But I guess, an Option of a reference never needs to allocate memory, because it’ll either be a pointer to a value (Some) or a pointer to null (None). Right?

Well, that explains why it’s technically possible.
As for why Option<&str> is preferrable then:
It hides away your internals. Your caller should only care whether they can get the value or not (Some vs. None), not what the precise reason is. That reason or your internal structure might change.

@larix

  • All
  • Subscribed
  • Moderated
  • Favorites
  • rust@programming.dev
  • rosin
  • thenastyranch
  • tacticalgear
  • ethstaker
  • InstantRegret
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • Youngstown
  • mdbf
  • khanakhh
  • slotface
  • GTA5RPClips
  • kavyap
  • JUstTest
  • everett
  • cisconetworking
  • Durango
  • modclub
  • osvaldo12
  • tester
  • Leos
  • cubers
  • normalnudes
  • megavids
  • anitta
  • provamag3
  • lostlight
  • All magazines