@@ -48,8 +48,28 @@ pub trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, Output = Self> {
4848 fn rem_euclid ( & self , v : & Self ) -> Self ;
4949}
5050
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+
5168macro_rules! euclid_int_impl {
5269 ( $( $t: ty) * ) => { $(
70+ euclid_forward_impl!( $t) ;
71+
72+ #[ cfg( not( has_div_euclid) ) ]
5373 impl Euclid for $t {
5474 #[ inline]
5575 fn div_euclid( & self , v: & $t) -> Self {
@@ -79,6 +99,9 @@ macro_rules! euclid_int_impl {
7999
80100macro_rules! euclid_uint_impl {
81101 ( $( $t: ty) * ) => { $(
102+ euclid_forward_impl!( $t) ;
103+
104+ #[ cfg( not( has_div_euclid) ) ]
82105 impl Euclid for $t {
83106 #[ inline]
84107 fn div_euclid( & self , v: & $t) -> Self {
@@ -100,6 +123,10 @@ euclid_int_impl!(i128);
100123#[ cfg( has_i128) ]
101124euclid_uint_impl ! ( u128 ) ;
102125
126+ #[ cfg( all( has_div_euclid, feature = "std" ) ) ]
127+ euclid_forward_impl ! ( f32 f64 ) ;
128+
129+ #[ cfg( not( all( has_div_euclid, feature = "std" ) ) ) ]
103130impl Euclid for f32 {
104131 #[ inline]
105132 fn div_euclid ( & self , v : & f32 ) -> f32 {
@@ -121,6 +148,7 @@ impl Euclid for f32 {
121148 }
122149}
123150
151+ #[ cfg( not( all( has_div_euclid, feature = "std" ) ) ) ]
124152impl Euclid for f64 {
125153 #[ inline]
126154 fn div_euclid ( & self , v : & f64 ) -> f64 {
@@ -152,8 +180,28 @@ pub trait CheckedEuclid: Euclid {
152180 fn checked_rem_euclid ( & self , v : & Self ) -> Option < Self > ;
153181}
154182
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+
155200macro_rules! checked_euclid_int_impl {
156201 ( $( $t: ty) * ) => { $(
202+ checked_euclid_forward_impl!( $t) ;
203+
204+ #[ cfg( not( has_div_euclid) ) ]
157205 impl CheckedEuclid for $t {
158206 #[ inline]
159207 fn checked_div_euclid( & self , v: & $t) -> Option <$t> {
@@ -178,6 +226,9 @@ macro_rules! checked_euclid_int_impl {
178226
179227macro_rules! checked_euclid_uint_impl {
180228 ( $( $t: ty) * ) => { $(
229+ checked_euclid_forward_impl!( $t) ;
230+
231+ #[ cfg( not( has_div_euclid) ) ]
181232 impl CheckedEuclid for $t {
182233 #[ inline]
183234 fn checked_div_euclid( & self , v: & $t) -> Option <$t> {
0 commit comments