Coverage Report

Created: 2025-11-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/parking_lot-0.12.5/src/util.rs
Line
Count
Source
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
0
    unsafe fn unchecked_unwrap(self) -> T {
18
0
        match self {
19
0
            Some(x) => x,
20
0
            None => unreachable(),
21
        }
22
0
    }
23
}
24
25
// hint::unreachable_unchecked() in release mode
26
#[inline]
27
0
unsafe fn unreachable() -> ! {
28
0
    if cfg!(debug_assertions) {
29
0
        unreachable!();
30
    } else {
31
0
        core::hint::unreachable_unchecked()
32
    }
33
}
34
35
#[inline]
36
0
pub fn to_deadline(timeout: Duration) -> Option<Instant> {
37
0
    Instant::now().checked_add(timeout)
38
0
}