rustils/impls/parse/
long_impl.rs

1use parse::long::*;
2use RoundingMode;
3
4impl ToI64 for bool {
5
6    /// Parse [`bool`](https://doc.rust-lang.org/std/primitive.bool.html) to
7    /// [`i64`](https://doc.rust-lang.org/std/primitive.i64.html)
8    /// (see more: [`bool_to_i64_res`](../../parse/long/fn.bool_to_i64_res.html))
9    ///
10    /// # Examples
11    ///
12    /// ```
13    /// use rustils::parse::long::ToI64;
14    ///
15    /// assert_eq!(true.to_i64_res(), Ok(1_i64));
16    /// assert_eq!(false.to_i64_res(), Ok(0_i64));
17    /// ```
18    fn to_i64_res(self)
19    -> ParseResultI64 {
20
21        bool_to_i64_res(self)
22    }
23
24    /// Parse [`bool`](https://doc.rust-lang.org/std/primitive.bool.html) to
25    /// [`i64`](https://doc.rust-lang.org/std/primitive.i64.html)
26    /// (see more: [`bool_to_i64`](../../parse/long/fn.bool_to_i64.html))
27    ///
28    /// # Examples
29    ///
30    /// ```
31    /// use rustils::parse::long::ToI64;
32    ///
33    /// assert_eq!(true.to_i64(), 1_i64);
34    /// assert_eq!(false.to_i64(), 0_i64);
35    /// ```
36    fn to_i64(self)
37        -> i64 {
38
39        bool_to_i64(self)
40    }
41}
42
43impl ToI64 for f32 {
44
45    fn to_i64_res(self)
46        -> ParseResultI64 {
47
48        f32_to_i64_res(self)
49    }
50
51    fn to_i64(self)
52        -> i64 {
53
54        f32_to_i64(self)
55    }
56}
57
58impl ToI64RM for f32 {
59
60    fn to_i64_rm_res(self, rm: RoundingMode)
61        -> ParseResultI64 {
62
63        f32_to_i64_rm_res(self, rm)
64    }
65
66    fn to_i64_rm(self, rm: RoundingMode)
67        -> i64 {
68
69        f32_to_i64_rm(self, rm)
70    }
71}
72
73impl ToI64 for u64 {
74
75    /// Parse [`u64`](https://doc.rust-lang.org/std/primitive.u64.html) to
76    /// [`i64`](https://doc.rust-lang.org/std/primitive.i64.html)
77    /// (see more: [`u64_to_i64_res`](../../parse/long/fn.u64_to_i64_res.html))
78    ///
79    /// # Examples
80    ///
81    /// ```
82    /// use rustils::parse::long::ToI64;
83    ///
84    /// assert_eq!(0_u64.to_i64_res(), Ok(0_i64));
85    /// assert_eq!(9223372036854775807_u64.to_i64_res(), Ok(9223372036854775807_i64));
86    /// ```
87    fn to_i64_res(self)
88        -> ParseResultI64 {
89
90        u64_to_i64_res(self)
91    }
92
93    /// Parse [`u64`](https://doc.rust-lang.org/std/primitive.u64.html) to
94    /// [`i64`](https://doc.rust-lang.org/std/primitive.i64.html)
95    /// (see more: [`u64_to_i64`](../../parse/long/fn.u64_to_i64.html))
96    ///
97    /// # Examples
98    ///
99    /// ```
100    /// use rustils::parse::long::ToI64;
101    ///
102    /// assert_eq!(0_u64.to_i64(), 0_i64);
103    /// assert_eq!(9223372036854775807_u64.to_i64(), 9223372036854775807_i64);
104    /// ```
105    fn to_i64(self)
106        -> i64 {
107
108        u64_to_i64(self)
109    }
110}
111
112impl ToI64 for f64 {
113
114    fn to_i64_res(self)
115    -> ParseResultI64 {
116
117        f64_to_i64_res(self)
118    }
119
120    fn to_i64(self)
121        -> i64 {
122
123        f64_to_i64(self)
124    }
125}
126
127impl ToI64RM for f64 {
128
129    fn to_i64_rm_res(self, rm: RoundingMode)
130        -> ParseResultI64 {
131
132        f64_to_i64_rm_res(self, rm)
133    }
134
135    fn to_i64_rm(self, rm: RoundingMode)
136        -> i64 {
137
138        f64_to_i64_rm(self, rm)
139    }
140}
141
142impl ToI64 for usize {
143
144    /// Parse [`usize`](https://doc.rust-lang.org/std/primitive.usize.html) to
145    /// [`i64`](https://doc.rust-lang.org/std/primitive.i64.html)
146    /// (see more: [`usize_to_i64_res`](../../parse/long/fn.usize_to_i64_res.html))
147    ///
148    /// # Examples
149    ///
150    /// ```
151    /// use rustils::parse::long::ToI64;
152    ///
153    /// assert_eq!(0_usize.to_i64_res(), Ok(0_i64));
154    /// assert_eq!(9223372036854775807_usize.to_i64_res(), Ok(9223372036854775807_i64));
155    /// ```
156    fn to_i64_res(self)
157        -> ParseResultI64 {
158
159        usize_to_i64_res(self)
160    }
161
162    /// Parse [`usize`](https://doc.rust-lang.org/std/primitive.usize.html) to
163    /// [`i64`](https://doc.rust-lang.org/std/primitive.i64.html)
164    /// (see more: [`usize_to_i64`](../../parse/long/fn.usize_to_i64.html))
165    ///
166    /// # Examples
167    ///
168    /// ```
169    /// use rustils::parse::long::ToI64;
170    ///
171    /// assert_eq!(0_usize.to_i64(), 0_i64);
172    /// assert_eq!(9223372036854775807_usize.to_i64(), 9223372036854775807_i64);
173    /// ```
174    fn to_i64(self)
175        -> i64 {
176
177        usize_to_i64(self)
178    }
179}
180
181impl ToI64 for String {
182
183    fn to_i64_res(self)
184        -> ParseResultI64 {
185
186        string_to_i64_res(self)
187    }
188
189    fn to_i64(self)
190        -> i64 {
191
192        string_to_i64(self)
193    }
194}
195
196impl ToI64 for &'static str {
197
198    fn to_i64_res(self)
199        -> ParseResultI64 {
200
201        str_to_i64_res(self)
202    }
203
204    fn to_i64(self)
205        -> i64 {
206
207        str_to_i64(self)
208    }
209}