Skip to content

Commit c5c0392

Browse files
authored
Unrolled build for rust-lang#138957
Rollup merge of rust-lang#138957 - Natural-selection1:update-Option-doc, r=Amanieu Update the index of Option to make the summary more comprehensive fix: rust-lang#138955 This PR and rust-lang#138968 are twin PR By the way, this is my first time contributing to rust, and I'm not a native English speaker, so any suggestions—whether about the wording in the docs or the contribution process itself—would be greatly appreciated!
2 parents 5c54aa7 + d0ac97d commit c5c0392

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

library/core/src/option.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@
162162
//! The [`is_some`] and [`is_none`] methods return [`true`] if the [`Option`]
163163
//! is [`Some`] or [`None`], respectively.
164164
//!
165+
//! The [`is_some_and`] and [`is_none_or`] methods apply the provided function
166+
//! to the contents of the [`Option`] to produce a boolean value.
167+
//! If this is [`None`] then a default result is returned instead without executing the function.
168+
//!
165169
//! [`is_none`]: Option::is_none
166170
//! [`is_some`]: Option::is_some
171+
//! [`is_some_and`]: Option::is_some_and
172+
//! [`is_none_or`]: Option::is_none_or
167173
//!
168174
//! ## Adapters for working with references
169175
//!
@@ -177,6 +183,10 @@
177183
//! <code>[Option]<[Pin]<[&]T>></code>
178184
//! * [`as_pin_mut`] converts from <code>[Pin]<[&mut] [Option]\<T>></code> to
179185
//! <code>[Option]<[Pin]<[&mut] T>></code>
186+
//! * [`as_slice`] returns a one-element slice of the contained value, if any.
187+
//! If this is [`None`], an empty slice is returned.
188+
//! * [`as_mut_slice`] returns a mutable one-element slice of the contained value, if any.
189+
//! If this is [`None`], an empty slice is returned.
180190
//!
181191
//! [&]: reference "shared reference"
182192
//! [&mut]: reference "mutable reference"
@@ -187,6 +197,8 @@
187197
//! [`as_pin_mut`]: Option::as_pin_mut
188198
//! [`as_pin_ref`]: Option::as_pin_ref
189199
//! [`as_ref`]: Option::as_ref
200+
//! [`as_slice`]: Option::as_slice
201+
//! [`as_mut_slice`]: Option::as_mut_slice
190202
//!
191203
//! ## Extracting the contained value
192204
//!
@@ -200,12 +212,15 @@
200212
//! (which must implement the [`Default`] trait)
201213
//! * [`unwrap_or_else`] returns the result of evaluating the provided
202214
//! function
215+
//! * [`unwrap_unchecked`] produces *[undefined behavior]*
203216
//!
204217
//! [`expect`]: Option::expect
205218
//! [`unwrap`]: Option::unwrap
206219
//! [`unwrap_or`]: Option::unwrap_or
207220
//! [`unwrap_or_default`]: Option::unwrap_or_default
208221
//! [`unwrap_or_else`]: Option::unwrap_or_else
222+
//! [`unwrap_unchecked`]: Option::unwrap_unchecked
223+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
209224
//!
210225
//! ## Transforming contained values
211226
//!
@@ -230,15 +245,17 @@
230245
//! * [`filter`] calls the provided predicate function on the contained
231246
//! value `t` if the [`Option`] is [`Some(t)`], and returns [`Some(t)`]
232247
//! if the function returns `true`; otherwise, returns [`None`]
233-
//! * [`flatten`] removes one level of nesting from an
234-
//! [`Option<Option<T>>`]
248+
//! * [`flatten`] removes one level of nesting from an [`Option<Option<T>>`]
249+
//! * [`inspect`] method takes ownership of the [`Option`] and applies
250+
//! the provided function to the contained value by reference if [`Some`]
235251
//! * [`map`] transforms [`Option<T>`] to [`Option<U>`] by applying the
236252
//! provided function to the contained value of [`Some`] and leaving
237253
//! [`None`] values unchanged
238254
//!
239255
//! [`Some(t)`]: Some
240256
//! [`filter`]: Option::filter
241257
//! [`flatten`]: Option::flatten
258+
//! [`inspect`]: Option::inspect
242259
//! [`map`]: Option::map
243260
//!
244261
//! These methods transform [`Option<T>`] to a value of a possibly
@@ -621,6 +638,10 @@ impl<T> Option<T> {
621638
///
622639
/// let x: Option<u32> = None;
623640
/// assert_eq!(x.is_some_and(|x| x > 1), false);
641+
///
642+
/// let x: Option<String> = Some("ownership".to_string());
643+
/// assert_eq!(x.as_ref().is_some_and(|x| x.len() > 1), true);
644+
/// println!("still alive {:?}", x);
624645
/// ```
625646
#[must_use]
626647
#[inline]
@@ -665,6 +686,10 @@ impl<T> Option<T> {
665686
///
666687
/// let x: Option<u32> = None;
667688
/// assert_eq!(x.is_none_or(|x| x > 1), true);
689+
///
690+
/// let x: Option<String> = Some("ownership".to_string());
691+
/// assert_eq!(x.as_ref().is_none_or(|x| x.len() > 1), true);
692+
/// println!("still alive {:?}", x);
668693
/// ```
669694
#[must_use]
670695
#[inline]

0 commit comments

Comments
 (0)