base_traits/traits/
is_infinity.rs

1// src/traits/is_infinity.rs : `IsInfinity`
2
3/// Trait defining instance method `is_infinity() : bool` that indicates
4/// whether the implementing type instance is conceptually (or actually)
5/// infinite.
6///
7/// # Additional Implementations on Foreign Types
8///
9/// ## Built-in Types
10///
11/// If the feature `"implement-IsInfinity-for-built_ins"`
12/// is defined (as it is by `"default"`), then this is also implemented
13/// for the following types:
14/// - [`f32`];
15/// - [`f64`];
16pub trait IsInfinity {
17    fn is_infinity(&self) -> bool;
18}
19
20
21#[cfg(all(not(test), not(feature = "nostd")))]
22impl<T : IsInfinity + ?Sized> IsInfinity for Box<T> {
23    fn is_infinity(&self) -> bool {
24        (**self).is_infinity()
25    }
26}
27
28#[cfg(all(not(test), not(feature = "nostd")))]
29impl<T : IsInfinity + ?Sized> IsInfinity for std::rc::Rc<T> {
30    fn is_infinity(&self) -> bool {
31        (**self).is_infinity()
32    }
33}
34
35
36#[cfg(feature = "implement-IsInfinity-for-built_ins")]
37mod impl_for_built_ins {
38    #![allow(non_snake_case)]
39
40    macro_rules! implement_IsInfinity_ {
41        ($type:tt) => {
42            impl super::IsInfinity for $type {
43                #[inline]
44                fn is_infinity(&self) -> bool {
45                    (*self).is_infinite()
46                }
47            }
48        };
49    }
50
51    implement_IsInfinity_!(f32);
52    implement_IsInfinity_!(f64);
53}
54
55
56// ///////////////////////////// end of file //////////////////////////// //
57