@@ -42,6 +42,31 @@ pub trait Step: PartialOrd + Sized {
42
42
fn sub_one ( & self ) -> Self ;
43
43
}
44
44
45
+ // These are still macro-generated because the integer literals resolve to different types.
46
+ macro_rules! step_identical_methods {
47
+ ( ) => {
48
+ #[ inline]
49
+ fn replace_one( & mut self ) -> Self {
50
+ mem:: replace( self , 1 )
51
+ }
52
+
53
+ #[ inline]
54
+ fn replace_zero( & mut self ) -> Self {
55
+ mem:: replace( self , 0 )
56
+ }
57
+
58
+ #[ inline]
59
+ fn add_one( & self ) -> Self {
60
+ Add :: add( * self , 1 )
61
+ }
62
+
63
+ #[ inline]
64
+ fn sub_one( & self ) -> Self {
65
+ Sub :: sub( * self , 1 )
66
+ }
67
+ }
68
+ }
69
+
45
70
macro_rules! step_impl_unsigned {
46
71
( $( $t: ty) * ) => ( $(
47
72
#[ unstable( feature = "step_trait" ,
@@ -59,25 +84,7 @@ macro_rules! step_impl_unsigned {
59
84
}
60
85
}
61
86
62
- #[ inline]
63
- fn replace_one( & mut self ) -> Self {
64
- mem:: replace( self , 1 )
65
- }
66
-
67
- #[ inline]
68
- fn replace_zero( & mut self ) -> Self {
69
- mem:: replace( self , 0 )
70
- }
71
-
72
- #[ inline]
73
- fn add_one( & self ) -> Self {
74
- Add :: add( * self , 1 )
75
- }
76
-
77
- #[ inline]
78
- fn sub_one( & self ) -> Self {
79
- Sub :: sub( * self , 1 )
80
- }
87
+ step_identical_methods!( ) ;
81
88
}
82
89
) * )
83
90
}
@@ -100,25 +107,7 @@ macro_rules! step_impl_signed {
100
107
}
101
108
}
102
109
103
- #[ inline]
104
- fn replace_one( & mut self ) -> Self {
105
- mem:: replace( self , 1 )
106
- }
107
-
108
- #[ inline]
109
- fn replace_zero( & mut self ) -> Self {
110
- mem:: replace( self , 0 )
111
- }
112
-
113
- #[ inline]
114
- fn add_one( & self ) -> Self {
115
- Add :: add( * self , 1 )
116
- }
117
-
118
- #[ inline]
119
- fn sub_one( & self ) -> Self {
120
- Sub :: sub( * self , 1 )
121
- }
110
+ step_identical_methods!( ) ;
122
111
}
123
112
) * )
124
113
}
@@ -134,25 +123,7 @@ macro_rules! step_impl_no_between {
134
123
None
135
124
}
136
125
137
- #[ inline]
138
- fn replace_one( & mut self ) -> Self {
139
- mem:: replace( self , 1 )
140
- }
141
-
142
- #[ inline]
143
- fn replace_zero( & mut self ) -> Self {
144
- mem:: replace( self , 0 )
145
- }
146
-
147
- #[ inline]
148
- fn add_one( & self ) -> Self {
149
- Add :: add( * self , 1 )
150
- }
151
-
152
- #[ inline]
153
- fn sub_one( & self ) -> Self {
154
- Sub :: sub( * self , 1 )
155
- }
126
+ step_identical_methods!( ) ;
156
127
}
157
128
) * )
158
129
}
0 commit comments