arbitrary_int/
v1_number_compat.rs1use crate::traits::{Integer, UnsignedInteger};
2use crate::TryNewError;
3use core::fmt::Debug;
4
5#[deprecated(
13 since = "2.0.0",
14 note = "Use [`UnsignedInteger`] or [`Integer`] instead. Suggested to import via `use arbitrary_int::prelude::*`."
15)]
16pub trait Number: UnsignedInteger<UnderlyingType = <Self as Number>::UnderlyingType> {
17 type UnderlyingType: Integer
18 + Debug
19 + From<u8>
20 + TryFrom<u16>
21 + TryFrom<u32>
22 + TryFrom<u64>
23 + TryFrom<u128>;
24
25 const BITS: usize = <Self as Integer>::BITS;
27
28 const MIN: Self = <Self as Integer>::MIN;
30
31 const MAX: Self = <Self as Integer>::MAX;
33
34 #[inline]
37 fn new(value: <Self as Number>::UnderlyingType) -> Self {
38 Integer::new(value)
39 }
40
41 #[inline]
43 fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError> {
44 Integer::try_new(value)
45 }
46
47 #[inline]
48 fn value(self) -> <Self as Number>::UnderlyingType {
49 Integer::value(self)
50 }
51
52 #[cfg(not(feature = "const_convert_and_const_trait_impl"))]
55 #[inline]
56 fn from_<T: Number>(value: T) -> Self {
57 Integer::from_(value)
58 }
59
60 #[cfg(not(feature = "const_convert_and_const_trait_impl"))]
63 #[inline]
64 fn masked_new<T: Number>(value: T) -> Self {
65 Integer::masked_new(value)
66 }
67
68 #[inline]
69 fn as_u8(&self) -> u8 {
70 Integer::as_u8(*self)
71 }
72
73 #[inline]
74 fn as_u16(&self) -> u16 {
75 Integer::as_u16(*self)
76 }
77
78 #[inline]
79 fn as_u32(&self) -> u32 {
80 Integer::as_u32(*self)
81 }
82
83 #[inline]
84 fn as_u64(&self) -> u64 {
85 Integer::as_u64(*self)
86 }
87
88 #[inline]
89 fn as_u128(&self) -> u128 {
90 Integer::as_u128(*self)
91 }
92
93 #[inline]
94 fn as_usize(&self) -> usize {
95 Integer::as_usize(*self)
96 }
97
98 #[cfg(not(feature = "const_convert_and_const_trait_impl"))]
99 #[inline]
100 fn as_<T: Number>(self) -> T {
101 Integer::as_(self)
102 }
103}