aboutsummaryrefslogtreecommitdiff
path: root/src/v1_47.rs
blob: d628abd0ad8e6505e146538c23778493371bdbaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::traits::Sealed;
use core::ops::{DerefMut, Range};

pub trait Range_v1_47<Idx>: Sealed<Range<Idx>> {
    fn is_empty(&self) -> bool;
}

impl<Idx: PartialOrd<Idx>> Range_v1_47<Idx> for Range<Idx> {
    fn is_empty(&self) -> bool {
        !(self.start < self.end)
    }
}

pub trait Result_v1_47<T: DerefMut, E>: Sealed<Result<T, E>> {
    fn as_deref(&self) -> Result<&T::Target, &E>;
    fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E>;
}

impl<T: DerefMut, E> Result_v1_47<T, E> for Result<T, E> {
    fn as_deref(&self) -> Result<&T::Target, &E> {
        self.as_ref().map(|t| t.deref())
    }

    fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> {
        self.as_mut().map(|t| t.deref_mut())
    }
}

#[cfg(feature = "std")]
pub trait Vec_v1_47<T>: Sealed<Vec<T>> {
    fn leak<'a>(self) -> &'a mut [T]
    where
        T: 'a;
}

#[cfg(feature = "std")]
impl<T> Vec_v1_47<T> for Vec<T> {
    #[inline]
    fn leak<'a>(self) -> &'a mut [T]
    where
        T: 'a,
    {
        Box::leak(self.into_boxed_slice())
    }
}

pub mod f32 {
    pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;
}

pub mod f64 {
    pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;
}