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
use crate::{
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8, Unwrapped, Wrapping,
};
use arbitrary::{Arbitrary, Result as ArbitraryResult, Unstructured};
macro_rules! impl_trait {
($Fixed:ident, $nbits:expr, $Inner:ident) => {
impl<'a, const FRAC: i32> Arbitrary<'a> for $Fixed<FRAC> {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> ArbitraryResult<Self> {
Ok(Self::from_bits(<$Inner as Arbitrary<'a>>::arbitrary(u)?))
}
#[inline]
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<$Inner as Arbitrary<'a>>::size_hint(depth)
}
}
impl<'a, const FRAC: i32> Arbitrary<'a> for Wrapping<$Fixed<FRAC>> {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> ArbitraryResult<Self> {
Ok(Self::from_bits(<$Inner as Arbitrary<'a>>::arbitrary(u)?))
}
#[inline]
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<$Inner as Arbitrary<'a>>::size_hint(depth)
}
}
impl<'a, const FRAC: i32> Arbitrary<'a> for Unwrapped<$Fixed<FRAC>> {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> ArbitraryResult<Self> {
Ok(Self::from_bits(<$Inner as Arbitrary<'a>>::arbitrary(u)?))
}
#[inline]
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<$Inner as Arbitrary<'a>>::size_hint(depth)
}
}
};
}
impl_trait! { FixedI8, 8, i8 }
impl_trait! { FixedI16, 16, i16 }
impl_trait! { FixedI32, 32, i32 }
impl_trait! { FixedI64, 64, i64 }
impl_trait! { FixedI128, 128, i128 }
impl_trait! { FixedU8, 8, u8 }
impl_trait! { FixedU16, 16, u16 }
impl_trait! { FixedU32, 32, u32 }
impl_trait! { FixedU64, 64, u64 }
impl_trait! { FixedU128, 128, u128 }