]>
git.proxmox.com Git - cargo.git/blob - vendor/thread_local/src/unreachable.rs
1 // Copyright 2017 Amanieu d'Antras
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // http://opensource.org/licenses/MIT>, at your option. This file may not be
6 // copied, modified, or distributed except according to those terms.
8 use std
::hint
::unreachable_unchecked
;
10 /// An extension trait for `Option<T>` providing unchecked unwrapping methods.
11 pub trait UncheckedOptionExt
<T
> {
12 /// Get the value out of this Option without checking for None.
13 unsafe fn unchecked_unwrap(self) -> T
;
15 /// Assert that this Option is a None to the optimizer.
16 unsafe fn unchecked_unwrap_none(self);
19 /// An extension trait for `Result<T, E>` providing unchecked unwrapping methods.
20 pub trait UncheckedResultExt
<T
, E
> {
21 /// Get the value out of this Result without checking for Err.
22 unsafe fn unchecked_unwrap_ok(self) -> T
;
24 /// Get the error out of this Result without checking for Ok.
25 unsafe fn unchecked_unwrap_err(self) -> E
;
28 impl<T
> UncheckedOptionExt
<T
> for Option
<T
> {
29 unsafe fn unchecked_unwrap(self) -> T
{
32 None
=> unreachable_unchecked(),
36 unsafe fn unchecked_unwrap_none(self) {
38 unreachable_unchecked()
43 impl<T
, E
> UncheckedResultExt
<T
, E
> for Result
<T
, E
> {
44 unsafe fn unchecked_unwrap_ok(self) -> T
{
47 Err(_
) => unreachable_unchecked(),
51 unsafe fn unchecked_unwrap_err(self) -> E
{
53 Ok(_
) => unreachable_unchecked(),