]> git.proxmox.com Git - rustc.git/blob - vendor/parking_lot/src/util.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / vendor / parking_lot / src / util.rs
1 // Copyright 2016 Amanieu d'Antras
2 //
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.
7
8 use std::time::{Duration, Instant};
9
10 // Option::unchecked_unwrap
11 pub trait UncheckedOptionExt<T> {
12 unsafe fn unchecked_unwrap(self) -> T;
13 }
14
15 impl<T> UncheckedOptionExt<T> for Option<T> {
16 #[inline]
17 unsafe fn unchecked_unwrap(self) -> T {
18 match self {
19 Some(x) => x,
20 None => unreachable(),
21 }
22 }
23 }
24
25 // hint::unreachable_unchecked() in release mode
26 #[inline]
27 unsafe fn unreachable() -> ! {
28 if cfg!(debug_assertions) {
29 unreachable!();
30 } else {
31 core::hint::unreachable_unchecked()
32 }
33 }
34
35 #[inline]
36 pub fn to_deadline(timeout: Duration) -> Option<Instant> {
37 Instant::now().checked_add(timeout)
38 }