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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/// Extention trait that enables `.into_type::<T>()` syntax. Also works for `cinto`, `try_into`, `saturating_into`.
///
/// When you replace unchecked type casts (e.g. `number as u32`) with an infallible conversion
/// (`number.into()`) or a fallible conversion (`number.try_into()?`), you may often encounter
/// type inference errors. The easiest way to solve it is to use `From` or `TryFrom` instead
/// so that you can specify the target type: `u32::from(number)`, `u32::try_from(number)?`.
///
/// However, if you don't want to rewrite your whole expression, you can use this extension trait
/// to specify the target type at the end: `number.into_type::<u32>()`, `number.cinto_type::<u32>()?`.
///
/// This trait is implemented for all types. However, each method has its own type bound that requires
/// the corresponding conversion trait to be implemented.
/// Checked conversion from `F` to `Self`.
///
/// This is semantically the same as [TryFrom](std::convert::TryFrom). However, `Cfrom`
/// aims to provide a rich error message, as opposed to many implementations of `TryFrom` in `std`
/// that provide minimal informations in errors.
///
/// Similar to `TryFrom`, it's recommended to always implement `Cfrom` instead of [`Cinto`](Cinto).
/// The corresponding `Cinto` implementation will be covered by the blanket impl.
/// Checked conversion from `Self` to `I`.
///
/// This trait is automatically implemented when `I` implements `Cfrom<Self>`.
///
/// See [`Cfrom`](Cfrom) for main documentation.
///
/// In order to help with type inference,
/// the [`IntoType`](IntoType) extension trait provides `.cinto_type::<T>()` syntax.
/// Saturating conversion of a number from `F` to `Self`.
///
/// If the value being converted is out of bounds for the target type,
/// the closest representable value is returned. Consequently, if the value is out of bounds,
/// this conversion always returns `Self::MIN` or `Self::MAX`.
///
/// Similar to [`TryFrom`](std::convert::TryFrom), it's recommended to always implement
/// `SaturatingFrom` instead of [`SaturatingInto`](Cinto).
/// The corresponding `SaturatingInto` implementation will be covered by the blanket impl.
/// Saturating conversion of a number from `Self` to `I`.
///
/// This trait is automatically implemented when `I` implements `SaturatingFrom<Self>`.
///
/// See [`SaturatingFrom`](SaturatingFrom) for main documentation.
///
/// In order to help with type inference,
/// the [`IntoType`](IntoType) extension trait provides `.saturating_into_type::<T>()` syntax.