larix

@larix@programming.dev

This profile is from a federated server and may be incomplete. Browse more on the original instance.

larix,

Thanks!

larix, (edited )

Thank you very much. I’ll change it. I did run cargo clippy, but it didn’t complained anything anymore before I published the code. 🙂

One question to return value Option<&String>:

is it better to change to Option<&str> or &Option<String> if the value in the struct is a Option<String>? The latter sounds more logical to me.

larix,

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.

Yes, that makes sense too. Great!

I’ve updated the code as recommended.

@Ephera@jcbritobr@mastodon.social

  • All
  • Subscribed
  • Moderated
  • Favorites
  • normalnudes
  • osvaldo12
  • magazineikmin
  • vwfavf
  • thenastyranch
  • Youngstown
  • slotface
  • Durango
  • ngwrru68w68
  • rosin
  • kavyap
  • tsrsr
  • PowerRangers
  • DreamBathrooms
  • Leos
  • khanakhh
  • hgfsjryuu7
  • cubers
  • everett
  • cisconetworking
  • InstantRegret
  • mdbf
  • tacticalgear
  • ethstaker
  • tester
  • modclub
  • GTA5RPClips
  • anitta
  • All magazines