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