Trait unwrap_none::UnwrapNone [−][src]
Required methods
fn expect_none(self, msg: &str)
[src]
Consumes self
while expecting None
and returning nothing.
Panics
Panics if the value is a Some
, with a panic message including the
passed message, and the content of the Some
.
Examples
#![feature(option_expect_none)] use std::collections::HashMap; let mut squares = HashMap::new(); for i in -10..=10 { // This will not panic, since all keys are unique. squares.insert(i, i * i).expect_none("duplicate key"); }
ⓘ
#![feature(option_expect_none)] use std::collections::HashMap; let mut sqrts = HashMap::new(); for i in -10..=10 { // This will panic, since both negative and positive `i` will // insert the same `i * i` key, returning the old `Some(i)`. sqrts.insert(i * i, i).expect_none("duplicate key"); }
fn unwrap_none(self)
[src]
Consumes self
while expecting None
and returning nothing.
Panics
Panics if the value is a Some
, with a custom panic message provided
by the Some
’s value.
Examples
#![feature(option_unwrap_none)] use std::collections::HashMap; let mut squares = HashMap::new(); for i in -10..=10 { // This will not panic, since all keys are unique. squares.insert(i, i * i).unwrap_none(); }
ⓘ
#![feature(option_unwrap_none)] use std::collections::HashMap; let mut sqrts = HashMap::new(); for i in -10..=10 { // This will panic, since both negative and positive `i` will // insert the same `i * i` key, returning the old `Some(i)`. sqrts.insert(i * i, i).unwrap_none(); }
Implementations on Foreign Types
impl<T> UnwrapNone for Option<T> where
T: Debug,
[src]
T: Debug,