Skip to content

Commit 1648415

Browse files
committed
add modify-in-place methods to option overview
1 parent 0401446 commit 1648415

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

core/src/option.rs

+29
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,35 @@
296296
//! }
297297
//! ```
298298
//!
299+
//! ## Modifying an [`Option`] in-place
300+
//!
301+
//! These methods return a mutable reference to the contained value of a
302+
//! [`Some`].
303+
//!
304+
//! * [`insert`] inserts a value, dropping any old contents
305+
//! * [`get_or_insert`] gets the current value, inserting a provided
306+
//! default value if it is [`None`]
307+
//! * [`get_or_insert_default`] gets the current value, inserting the
308+
//! default value of type `T` if it is [`None`]
309+
//! * [`get_or_insert_with`] gets the current value, inserting a default
310+
//! computed by the provided function if it is [`None`]
311+
//!
312+
//! [`insert`]: Option::insert
313+
//! [`get_or_insert`]: Option::get_or_insert
314+
//! [`get_or_insert_default`]: Option::get_or_insert_default
315+
//! [`get_or_insert_with`]: Option::get_or_insert_with
316+
//!
317+
//! These methods transfer ownership of the [`Option`].
318+
//!
319+
//! * [`take`] takes ownership of the [`Option`], including any contained
320+
//! value, replacing it with [`None`]
321+
//! * [`replace`] takes ownership of the [`Option`], including any
322+
//! contained value, replacing it with a [`Some`] containing the provided
323+
//! value
324+
//!
325+
//! [`take`]: Option::take
326+
//! [`replace`]: Option::replace
327+
//!
299328
//! # Examples
300329
//!
301330
//! Basic pattern matching on [`Option`]:

0 commit comments

Comments
 (0)