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
use *;
// Similar to Trait From / Into, but those trait suppose no loss when converting, so it is impossible to cast a f32 to a i64 for exemple
/// Might lose some precision.
/// Same semantics as the [`as`](https://practice.course.rs/type-conversions/as.html) keyword: `4f32 as u64`
// Double recursive macro :)
// Do 144 trait impl in a few lines :)
map_on_number!;
/*
// If you also want to support bool
macro_rules! impl_cast_to_bool
{
($itself: ty) =>
{
impl CastInto<bool> for $itself
{
fn cast_to(self) -> bool { self == (0 as $itself) }
}
};
}
map_on_number!(impl_cast_to_bool);
impl CastInto<bool> for bool { fn cast_to(self) -> bool { self } }
*/