// Copyright 2017 Amanieu d'Antras // // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms.
use std::hint::unreachable_unchecked;
/// An extension trait for `Option<T>` providing unchecked unwrapping methods. pubtrait UncheckedOptionExt<T> { /// Get the value out of this Option without checking for None. unsafefn unchecked_unwrap(self) -> T;
/// Assert that this Option is a None to the optimizer. unsafefn unchecked_unwrap_none(self);
}
/// An extension trait for `Result<T, E>` providing unchecked unwrapping methods. pubtrait UncheckedResultExt<T, E> { /// Get the value out of this Result without checking for Err. unsafefn unchecked_unwrap_ok(self) -> T;
/// Get the error out of this Result without checking for Ok. unsafefn unchecked_unwrap_err(self) -> E;
}
impl<T> UncheckedOptionExt<T> for Option<T> { unsafefn unchecked_unwrap(self) -> T { matchself {
Some(x) => x,
None => unreachable_unchecked(),
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.