|
159 | 159 | //! |
160 | 160 | //! ## Querying the variant |
161 | 161 | //! |
162 | | -//! The [`is_some`] and [`is_none`] methods return [`true`] if the [`Option`] |
163 | | -//! is [`Some`] or [`None`], respectively. |
| 162 | +//! The [`is_some`] and [`is_none`] methods take a borrow of the [`Option`] |
| 163 | +//! and return [`true`] if the [`Option`] is [`Some`] or [`None`], respectively. |
| 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. |
164 | 168 | //! |
165 | 169 | //! [`is_none`]: Option::is_none |
166 | 170 | //! [`is_some`]: Option::is_some |
| 171 | +//! [`is_some_and`]: Option::is_some_and |
| 172 | +//! [`is_none_or`]: Option::is_none_or |
167 | 173 | //! |
168 | 174 | //! ## Adapters for working with references |
169 | 175 | //! |
|
177 | 183 | //! <code>[Option]<[Pin]<[&]T>></code> |
178 | 184 | //! * [`as_pin_mut`] converts from <code>[Pin]<[&mut] [Option]\<T>></code> to |
179 | 185 | //! <code>[Option]<[Pin]<[&mut] T>></code> |
| 186 | +//! * [`as_slice`] returns a slice of the contained value, if any. |
| 187 | +//! If this is [`None`], an empty slice is returned. |
| 188 | +//! * [`as_mut_slice`] returns a mutable slice of the contained value, if any. |
| 189 | +//! If this is [`None`], an empty slice is returned. |
180 | 190 | //! |
181 | 191 | //! [&]: reference "shared reference" |
182 | 192 | //! [&mut]: reference "mutable reference" |
|
187 | 197 | //! [`as_pin_mut`]: Option::as_pin_mut |
188 | 198 | //! [`as_pin_ref`]: Option::as_pin_ref |
189 | 199 | //! [`as_ref`]: Option::as_ref |
| 200 | +//! [`as_slice`]: Option::as_slice |
| 201 | +//! [`as_mut_slice`]: Option::as_mut_slice |
190 | 202 | //! |
191 | 203 | //! ## Extracting the contained value |
192 | 204 | //! |
|
200 | 212 | //! (which must implement the [`Default`] trait) |
201 | 213 | //! * [`unwrap_or_else`] returns the result of evaluating the provided |
202 | 214 | //! function |
| 215 | +//! * [`unwrap_unchecked`] returns the contained value, without checking |
| 216 | +//! calling this method on None is *[undefined behavior]* |
203 | 217 | //! |
204 | 218 | //! [`expect`]: Option::expect |
205 | 219 | //! [`unwrap`]: Option::unwrap |
206 | 220 | //! [`unwrap_or`]: Option::unwrap_or |
207 | 221 | //! [`unwrap_or_default`]: Option::unwrap_or_default |
208 | 222 | //! [`unwrap_or_else`]: Option::unwrap_or_else |
| 223 | +//! [`unwrap_unchecked`]: Option::unwrap_unchecked |
| 224 | +//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html |
209 | 225 | //! |
210 | 226 | //! ## Transforming contained values |
211 | 227 | //! |
|
232 | 248 | //! if the function returns `true`; otherwise, returns [`None`] |
233 | 249 | //! * [`flatten`] removes one level of nesting from an |
234 | 250 | //! [`Option<Option<T>>`] |
| 251 | +//! * [`insert`] calls the provided function with a reference to |
| 252 | +//! the contained value if [`Some`] |
235 | 253 | //! * [`map`] transforms [`Option<T>`] to [`Option<U>`] by applying the |
236 | 254 | //! provided function to the contained value of [`Some`] and leaving |
237 | 255 | //! [`None`] values unchanged |
238 | 256 | //! |
239 | 257 | //! [`Some(t)`]: Some |
240 | 258 | //! [`filter`]: Option::filter |
241 | 259 | //! [`flatten`]: Option::flatten |
| 260 | +//! [`insert`]: Option::insert |
242 | 261 | //! [`map`]: Option::map |
243 | 262 | //! |
244 | 263 | //! These methods transform [`Option<T>`] to a value of a possibly |
|
0 commit comments