|
159 | 159 | //!
|
160 | 160 | //! ## Querying the variant
|
161 | 161 | //!
|
162 |
| -//! The [`is_some`] and [`is_none`] methods take a borrow of the [`Option`] |
| 162 | +//! The [`is_some`] and [`is_none`] methods borrow of the [`Option`] |
163 | 163 | //! and return [`true`] if the [`Option`] is [`Some`] or [`None`], respectively.
|
164 | 164 | //!
|
165 |
| -//! The [`is_some_and`] and [`is_none_or`] methods take ownership of the [`Option`] |
166 |
| -//! and apply the provided function to make a decision. |
167 |
| -//! The methods return the same boolean value as the function returns. |
| 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 | 168 | //!
|
169 | 169 | //! [`is_none`]: Option::is_none
|
170 | 170 | //! [`is_some`]: Option::is_some
|
171 | 171 | //! [`is_some_and`]: Option::is_some_and
|
172 | 172 | //! [`is_none_or`]: Option::is_none_or
|
173 | 173 | //!
|
174 |
| -//! ## Inspecting the variant |
175 |
| -//! |
176 |
| -//! The [`inspect`] method takes ownership of the [`Option`] |
177 |
| -//! and applies the provided function to the contained value by reference if [`Some`] |
178 |
| -//! |
179 |
| -//! [`inspect`]: Option::inspect |
180 |
| -//! |
181 | 174 | //! ## Adapters for working with references
|
182 | 175 | //!
|
183 | 176 | //! * [`as_ref`] converts from <code>[&][][Option]\<T></code> to <code>[Option]<[&]T></code>
|
|
190 | 183 | //! <code>[Option]<[Pin]<[&]T>></code>
|
191 | 184 | //! * [`as_pin_mut`] converts from <code>[Pin]<[&mut] [Option]\<T>></code> to
|
192 | 185 | //! <code>[Option]<[Pin]<[&mut] T>></code>
|
193 |
| -//! * [`as_slice`] returns a slice of the contained value, if any. |
| 186 | +//! * [`as_slice`] returns a one-element slice of the contained value, if any. |
194 | 187 | //! If this is [`None`], an empty slice is returned.
|
195 |
| -//! * [`as_mut_slice`] returns a mutable slice of the contained value, if any. |
| 188 | +//! * [`as_mut_slice`] returns a mutable one-element slice of the contained value, if any. |
196 | 189 | //! If this is [`None`], an empty slice is returned.
|
197 | 190 | //!
|
198 | 191 | //! [&]: reference "shared reference"
|
|
219 | 212 | //! (which must implement the [`Default`] trait)
|
220 | 213 | //! * [`unwrap_or_else`] returns the result of evaluating the provided
|
221 | 214 | //! function
|
222 |
| -//! * [`unwrap_unchecked`] returns the contained value, without checking |
223 |
| -//! calling this method on None is *[undefined behavior]* |
| 215 | +//! * [`unwrap_unchecked`] produces *[undefined behavior]* |
224 | 216 | //!
|
225 | 217 | //! [`expect`]: Option::expect
|
226 | 218 | //! [`unwrap`]: Option::unwrap
|
|
253 | 245 | //! * [`filter`] calls the provided predicate function on the contained
|
254 | 246 | //! value `t` if the [`Option`] is [`Some(t)`], and returns [`Some(t)`]
|
255 | 247 | //! if the function returns `true`; otherwise, returns [`None`]
|
256 |
| -//! * [`flatten`] removes one level of nesting from an |
257 |
| -//! [`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`] |
258 | 251 | //! * [`map`] transforms [`Option<T>`] to [`Option<U>`] by applying the
|
259 | 252 | //! provided function to the contained value of [`Some`] and leaving
|
260 | 253 | //! [`None`] values unchanged
|
261 | 254 | //!
|
262 | 255 | //! [`Some(t)`]: Some
|
263 | 256 | //! [`filter`]: Option::filter
|
264 | 257 | //! [`flatten`]: Option::flatten
|
| 258 | +//! [`inspect`]: Option::inspect |
265 | 259 | //! [`map`]: Option::map
|
266 | 260 | //!
|
267 | 261 | //! These methods transform [`Option<T>`] to a value of a possibly
|
|
0 commit comments