]>
Commit | Line | Data |
---|---|---|
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 |
8 | use instant::Instant; |
9 | use std::time::Duration; | |
9fa01778 | 10 | |
83c7162d XL |
11 | // Option::unchecked_unwrap |
12 | pub trait UncheckedOptionExt<T> { | |
13 | unsafe fn unchecked_unwrap(self) -> T; | |
14 | } | |
15 | ||
16 | impl<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] |
28 | unsafe 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] | |
37 | pub fn to_deadline(timeout: Duration) -> Option<Instant> { | |
72b1a166 | 38 | Instant::now().checked_add(timeout) |
9fa01778 | 39 | } |