@@ -120,21 +120,21 @@ macro_rules! newtype_index {
120
120
impl $type {
121
121
$v const MAX_AS_U32 : u32 = $max;
122
122
123
- $v const MAX : $type = $type :: from_u32_const( $max) ;
123
+ $v const MAX : Self = Self :: from_u32_const( $max) ;
124
124
125
125
#[ inline]
126
126
$v fn from_usize( value: usize ) -> Self {
127
127
assert!( value <= ( $max as usize ) ) ;
128
128
unsafe {
129
- $type :: from_u32_unchecked( value as u32 )
129
+ Self :: from_u32_unchecked( value as u32 )
130
130
}
131
131
}
132
132
133
133
#[ inline]
134
134
$v fn from_u32( value: u32 ) -> Self {
135
135
assert!( value <= $max) ;
136
136
unsafe {
137
- $type :: from_u32_unchecked( value)
137
+ Self :: from_u32_unchecked( value)
138
138
}
139
139
}
140
140
@@ -152,13 +152,13 @@ macro_rules! newtype_index {
152
152
] ;
153
153
154
154
unsafe {
155
- $type { private: value }
155
+ Self { private: value }
156
156
}
157
157
}
158
158
159
159
#[ inline]
160
160
$v const unsafe fn from_u32_unchecked( value: u32 ) -> Self {
161
- $type { private: value }
161
+ Self { private: value }
162
162
}
163
163
164
164
/// Extracts the value of this index as an integer.
@@ -184,14 +184,14 @@ macro_rules! newtype_index {
184
184
type Output = Self ;
185
185
186
186
fn add( self , other: usize ) -> Self {
187
- Self :: new ( self . index( ) + other)
187
+ Self :: from_usize ( self . index( ) + other)
188
188
}
189
189
}
190
190
191
- impl Idx for $type {
191
+ impl $crate :: vec :: Idx for $type {
192
192
#[ inline]
193
193
fn new( value: usize ) -> Self {
194
- Self :: from ( value)
194
+ Self :: from_usize ( value)
195
195
}
196
196
197
197
#[ inline]
@@ -204,39 +204,39 @@ macro_rules! newtype_index {
204
204
#[ inline]
205
205
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
206
206
<usize as :: std:: iter:: Step >:: steps_between(
207
- & Idx :: index( * start) ,
208
- & Idx :: index( * end) ,
207
+ & Self :: index( * start) ,
208
+ & Self :: index( * end) ,
209
209
)
210
210
}
211
211
212
212
#[ inline]
213
213
fn replace_one( & mut self ) -> Self {
214
- :: std:: mem:: replace( self , Self :: new ( 1 ) )
214
+ :: std:: mem:: replace( self , Self :: from_u32 ( 1 ) )
215
215
}
216
216
217
217
#[ inline]
218
218
fn replace_zero( & mut self ) -> Self {
219
- :: std:: mem:: replace( self , Self :: new ( 0 ) )
219
+ :: std:: mem:: replace( self , Self :: from_u32 ( 0 ) )
220
220
}
221
221
222
222
#[ inline]
223
223
fn add_one( & self ) -> Self {
224
- Self :: new ( Idx :: index( * self ) + 1 )
224
+ Self :: from_usize ( Self :: index( * self ) + 1 )
225
225
}
226
226
227
227
#[ inline]
228
228
fn sub_one( & self ) -> Self {
229
- Self :: new ( Idx :: index( * self ) - 1 )
229
+ Self :: from_usize ( Self :: index( * self ) - 1 )
230
230
}
231
231
232
232
#[ inline]
233
233
fn add_usize( & self , u: usize ) -> Option <Self > {
234
- Idx :: index( * self ) . checked_add( u) . map( Self :: new )
234
+ Self :: index( * self ) . checked_add( u) . map( Self :: from_usize )
235
235
}
236
236
237
237
#[ inline]
238
238
fn sub_usize( & self , u: usize ) -> Option <Self > {
239
- Idx :: index( * self ) . checked_sub( u) . map( Self :: new )
239
+ Self :: index( * self ) . checked_sub( u) . map( Self :: from_usize )
240
240
}
241
241
}
242
242
@@ -257,14 +257,14 @@ macro_rules! newtype_index {
257
257
impl From <usize > for $type {
258
258
#[ inline]
259
259
fn from( value: usize ) -> Self {
260
- $type :: from_usize( value)
260
+ Self :: from_usize( value)
261
261
}
262
262
}
263
263
264
264
impl From <u32 > for $type {
265
265
#[ inline]
266
266
fn from( value: u32 ) -> Self {
267
- $type :: from_u32( value)
267
+ Self :: from_u32( value)
268
268
}
269
269
}
270
270
@@ -409,7 +409,7 @@ macro_rules! newtype_index {
409
409
( @decodable $type: ident) => (
410
410
impl :: rustc_serialize:: Decodable for $type {
411
411
fn decode<D : :: rustc_serialize:: Decoder >( d: & mut D ) -> Result <Self , D :: Error > {
412
- d. read_u32( ) . map( Self :: from )
412
+ d. read_u32( ) . map( Self :: from_u32 )
413
413
}
414
414
}
415
415
) ;
@@ -500,7 +500,7 @@ macro_rules! newtype_index {
500
500
const $name: ident = $constant: expr,
501
501
$( $tokens: tt) * ) => (
502
502
$( #[ doc = $doc] ) *
503
- pub const $name: $type = $type:: from_u32_const( $constant) ;
503
+ $v const $name: $type = $type:: from_u32_const( $constant) ;
504
504
$crate:: newtype_index!(
505
505
@derives [ $( $derives, ) * ]
506
506
@attrs [ $( #[ $attrs] ) * ]
@@ -839,3 +839,6 @@ impl<I: Idx> FnMut<(usize,)> for IntoIdx<I> {
839
839
I :: new ( n)
840
840
}
841
841
}
842
+
843
+ #[ cfg( test) ]
844
+ mod tests;
0 commit comments