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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Author --- daniel.bechaz@gmail.com  
//! Last Moddified --- 2019-05-06

use super::*;

/// A marker trait for types which have a [NonZero] equivilant.
pub trait Number: Copy + Sized {
  /// The [NonZero] equivilant.
  type NonZero: NonZero<Self>;

  /// The zero value of this type.
  const ZERO: Self;
}

impl Number for usize {
  type NonZero = NonZeroUsize;

  const ZERO: Self = 0;
}

impl Number for u8 {
  type NonZero = NonZeroU8;

  const ZERO: Self = 0;
}

impl Number for u16 {
  type NonZero = NonZeroU16;

  const ZERO: Self = 0;
}

impl Number for u32 {
  type NonZero = NonZeroU32;

  const ZERO: Self = 0;
}

impl Number for u64 {
  type NonZero = NonZeroU64;

  const ZERO: Self = 0;
}

impl Number for u128 {
  type NonZero = NonZeroU128;

  const ZERO: Self = 0;
}

impl Number for isize {
  type NonZero = NonZeroIsize;

  const ZERO: Self = 0;
}

impl Number for i8 {
  type NonZero = NonZeroI8;

  const ZERO: Self = 0;
}

impl Number for i16 {
  type NonZero = NonZeroI16;

  const ZERO: Self = 0;
}

impl Number for i32 {
  type NonZero = NonZeroI32;

  const ZERO: Self = 0;
}

impl Number for i64 {
  type NonZero = NonZeroI64;

  const ZERO: Self = 0;
}

impl Number for i128 {
  type NonZero = NonZeroI128;

  const ZERO: Self = 0;
}

impl Number for f32 {
  type NonZero = NonZeroU32;

  const ZERO: Self = 0.0;
}

impl Number for f64 {
  type NonZero = NonZeroU64;

  const ZERO: Self = 0.0;
}