]>
git.proxmox.com Git - rustc.git/blob - vendor/parking_lot/src/util.rs
1 // Copyright 2016 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
::time
::{Duration, Instant}
;
10 // Option::unchecked_unwrap
11 pub trait UncheckedOptionExt
<T
> {
12 unsafe fn unchecked_unwrap(self) -> T
;
15 impl<T
> UncheckedOptionExt
<T
> for Option
<T
> {
17 unsafe fn unchecked_unwrap(self) -> T
{
20 None
=> unreachable(),
25 // hint::unreachable_unchecked() in release mode
27 unsafe fn unreachable() -> ! {
28 if cfg
!(debug_assertions
) {
31 core
::hint
::unreachable_unchecked()
36 pub fn to_deadline(timeout
: Duration
) -> Option
<Instant
> {
37 Instant
::now().checked_add(timeout
)