4

Github Tracking Issue for feature: "option_insert" · Issue #78271 · ru...

 3 years ago
source link: https://github.com/rust-lang/rust/issues/78271
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Contributor

Canop commented on Oct 23, 2020

edited by m-ou-se

This is a tracking issue for the feature "option_insert".
The feature gate for the issue is #[unstable(feature = "option_insert")].

This feature adds a insert method to any Option, setting its value and returning a mutable reference to this value.
This method removes a cause of unwrap and code complexity.
It allows replacing

option_value = Some(build());
option_value.as_mut().unwrap()
option_value.insert(build())

Steps

  • Decide on a name. Suggestions:
    • insert (As in the original PR.)
    • insert_and_get
    • replace
    • replace_and_get
    • set
  • Stabilization PR

Implementation history


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK