@@ -48,8 +48,28 @@ pub trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, Output = Self> {
48
48
fn rem_euclid ( & self , v : & Self ) -> Self ;
49
49
}
50
50
51
+ macro_rules! euclid_forward_impl {
52
+ ( $( $t: ty) * ) => { $(
53
+ #[ cfg( has_div_euclid) ]
54
+ impl Euclid for $t {
55
+ #[ inline]
56
+ fn div_euclid( & self , v: & $t) -> Self {
57
+ <$t>:: div_euclid( * self , * v)
58
+ }
59
+
60
+ #[ inline]
61
+ fn rem_euclid( & self , v: & $t) -> Self {
62
+ <$t>:: rem_euclid( * self , * v)
63
+ }
64
+ }
65
+ ) * }
66
+ }
67
+
51
68
macro_rules! euclid_int_impl {
52
69
( $( $t: ty) * ) => { $(
70
+ euclid_forward_impl!( $t) ;
71
+
72
+ #[ cfg( not( has_div_euclid) ) ]
53
73
impl Euclid for $t {
54
74
#[ inline]
55
75
fn div_euclid( & self , v: & $t) -> Self {
@@ -79,6 +99,9 @@ macro_rules! euclid_int_impl {
79
99
80
100
macro_rules! euclid_uint_impl {
81
101
( $( $t: ty) * ) => { $(
102
+ euclid_forward_impl!( $t) ;
103
+
104
+ #[ cfg( not( has_div_euclid) ) ]
82
105
impl Euclid for $t {
83
106
#[ inline]
84
107
fn div_euclid( & self , v: & $t) -> Self {
@@ -100,6 +123,10 @@ euclid_int_impl!(i128);
100
123
#[ cfg( has_i128) ]
101
124
euclid_uint_impl ! ( u128 ) ;
102
125
126
+ #[ cfg( all( has_div_euclid, feature = "std" ) ) ]
127
+ euclid_forward_impl ! ( f32 f64 ) ;
128
+
129
+ #[ cfg( not( all( has_div_euclid, feature = "std" ) ) ) ]
103
130
impl Euclid for f32 {
104
131
#[ inline]
105
132
fn div_euclid ( & self , v : & f32 ) -> f32 {
@@ -121,6 +148,7 @@ impl Euclid for f32 {
121
148
}
122
149
}
123
150
151
+ #[ cfg( not( all( has_div_euclid, feature = "std" ) ) ) ]
124
152
impl Euclid for f64 {
125
153
#[ inline]
126
154
fn div_euclid ( & self , v : & f64 ) -> f64 {
@@ -152,8 +180,28 @@ pub trait CheckedEuclid: Euclid {
152
180
fn checked_rem_euclid ( & self , v : & Self ) -> Option < Self > ;
153
181
}
154
182
183
+ macro_rules! checked_euclid_forward_impl {
184
+ ( $( $t: ty) * ) => { $(
185
+ #[ cfg( has_div_euclid) ]
186
+ impl CheckedEuclid for $t {
187
+ #[ inline]
188
+ fn checked_div_euclid( & self , v: & $t) -> Option <Self > {
189
+ <$t>:: checked_div_euclid( * self , * v)
190
+ }
191
+
192
+ #[ inline]
193
+ fn checked_rem_euclid( & self , v: & $t) -> Option <Self > {
194
+ <$t>:: checked_rem_euclid( * self , * v)
195
+ }
196
+ }
197
+ ) * }
198
+ }
199
+
155
200
macro_rules! checked_euclid_int_impl {
156
201
( $( $t: ty) * ) => { $(
202
+ checked_euclid_forward_impl!( $t) ;
203
+
204
+ #[ cfg( not( has_div_euclid) ) ]
157
205
impl CheckedEuclid for $t {
158
206
#[ inline]
159
207
fn checked_div_euclid( & self , v: & $t) -> Option <$t> {
@@ -178,6 +226,9 @@ macro_rules! checked_euclid_int_impl {
178
226
179
227
macro_rules! checked_euclid_uint_impl {
180
228
( $( $t: ty) * ) => { $(
229
+ checked_euclid_forward_impl!( $t) ;
230
+
231
+ #[ cfg( not( has_div_euclid) ) ]
181
232
impl CheckedEuclid for $t {
182
233
#[ inline]
183
234
fn checked_div_euclid( & self , v: & $t) -> Option <$t> {
0 commit comments