@@ -123,140 +123,116 @@ pub trait BitsMut: Bits {
123123 }
124124}
125125
126- macro_rules! impl_bits_for {
127- ( $( $t: ty ) ,* ) => { $(
128- impl <C > AsMut <BitSlice <C , $t>> for $t
129- where C : Cursor {
130- fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
131- BitsMut :: bits_mut( self )
132- }
133- }
134-
135- impl <C > AsRef <BitSlice <C , $t>> for $t
136- where C : Cursor {
137- fn as_ref( & self ) -> & BitSlice <C , $t> {
138- Bits :: bits( self )
139- }
140- }
141-
142- impl Bits for $t {
143- type Store = $t;
144-
145- fn bits<C >( & self ) -> & BitSlice <C , Self :: Store >
126+ impl < T > Bits for T
127+ where T : BitStore {
128+ type Store = T ;
129+ fn bits < C > ( & self ) -> & BitSlice < C , T >
146130 where C : Cursor {
147131 BitSlice :: from_element ( self )
148132 }
149133}
150134
151- impl BitsMut for $t {
152- fn bits_mut<C >( & mut self ) -> & mut BitSlice <C , Self :: Store >
135+ impl < T > BitsMut for T
136+ where T : BitStore {
137+ fn bits_mut < C > ( & mut self ) -> & mut BitSlice < C , T >
153138 where C : Cursor {
154139 BitSlice :: from_element_mut ( self )
155140 }
156141}
157142
158- impl <C > AsMut <BitSlice <C , $t>> for [ $t]
159- where C : Cursor {
160- fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
161- BitsMut :: bits_mut( self )
162- }
163- }
164-
165- impl <C > AsRef <BitSlice <C , $t>> for [ $t]
166- where C : Cursor {
167- fn as_ref( & self ) -> & BitSlice <C , $t> {
168- Bits :: bits( self )
169- }
170- }
171-
172- impl Bits for [ $t] {
173- type Store = $t;
174-
175- fn bits<C >( & self ) -> & BitSlice <C , Self :: Store >
143+ impl < T > Bits for [ T ]
144+ where T : BitStore {
145+ type Store = T ;
146+ fn bits < C > ( & self ) -> & BitSlice < C , T >
176147 where C : Cursor {
177148 BitSlice :: from_slice ( self )
178149 }
179150}
180151
181- impl BitsMut for [ $t] {
182- fn bits_mut<C >( & mut self ) -> & mut BitSlice <C , Self :: Store >
152+ impl < T > BitsMut for [ T ]
153+ where T : BitStore {
154+ fn bits_mut < C > ( & mut self ) -> & mut BitSlice < C , T >
183155 where C : Cursor {
184156 BitSlice :: from_slice_mut ( self )
185157 }
186158}
187159
188- impl <C > AsMut <BitSlice <C , $t>> for [ $t; 0 ]
189- where C : Cursor {
190- fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
191- BitsMut :: bits_mut( self )
192- }
193- }
194-
195- impl <C > AsRef <BitSlice <C , $t>> for [ $t; 0 ]
196- where C : Cursor {
197- fn as_ref( & self ) -> & BitSlice <C , $t> {
198- Bits :: bits( self )
199- }
200- }
201-
202- impl Bits for [ $t; 0 ] {
203- type Store = $t;
204-
205- fn bits<C >( & self ) -> & BitSlice <C , Self :: Store >
206- where C : Cursor {
207- BitSlice :: empty( )
208- }
209- }
210-
211- impl BitsMut for [ $t; 0 ] {
212- fn bits_mut<C >( & mut self ) -> & mut BitSlice <C , Self :: Store >
213- where C : Cursor {
214- BitSlice :: empty_mut( )
215- }
216- }
217-
218- impl_bits_for! { array $t ;
219- 1 2 3 4 5 6 7 8 9
220- 10 11 12 13 14 15 16 17 18 19
221- 20 21 22 23 24 25 26 27 28 29
222- 30 31 32 // going above 32 is a DoS attack on the compiler
223- }
160+ macro_rules! impl_bits_for {
161+ ( n $( $n: expr ) ,* ) => { $(
162+ impl <T > Bits for [ T ; $n]
163+ where T : BitStore {
164+ type Store = T ;
165+ fn bits<C >( & self ) -> & BitSlice <C , T >
166+ where C : Cursor {
167+ BitSlice :: from_slice( self )
168+ }
169+ }
170+ impl <T > BitsMut for [ T ; $n]
171+ where T : BitStore {
172+ fn bits_mut<C >( & mut self ) -> & mut BitSlice <C , T >
173+ where C : Cursor {
174+ BitSlice :: from_slice_mut( self )
175+ }
176+ }
224177 ) * } ;
225-
226- ( array $t: ty ; $( $n: expr ) * ) => { $(
227- impl <C > AsMut <BitSlice <C , $t>> for [ $t; $n]
228- where C : Cursor {
229- fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
230- BitsMut :: bits_mut( self )
231- }
232- }
233-
234- impl <C > AsRef <BitSlice <C , $t>> for [ $t; $n]
235- where C : Cursor {
236- fn as_ref( & self ) -> & BitSlice <C , $t> {
237- Bits :: bits( self )
238- }
239- }
240-
241- impl Bits for [ $t; $n] {
242- type Store = $t;
243-
244- fn bits<C >( & self ) -> & BitSlice <C , Self :: Store >
245- where C : Cursor {
246- BitSlice :: from_slice( & self [ ..] )
247- }
248- }
249-
250- impl BitsMut for [ $t; $n] {
251- fn bits_mut<C >( & mut self ) -> & mut BitSlice <C , Self :: Store >
252- where C : Cursor {
253- BitSlice :: from_slice_mut( & mut self [ ..] )
254- }
255- }
178+ ( t $( $t: ty ) ,* ) => { $(
179+ impl <C > AsMut <BitSlice <C , $t>> for $t
180+ where C : Cursor {
181+ fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
182+ BitSlice :: from_element_mut( self )
183+ }
184+ }
185+ impl <C > AsRef <BitSlice <C , $t>> for $t
186+ where C : Cursor {
187+ fn as_ref( & self ) -> & BitSlice <C , $t> {
188+ BitSlice :: from_element( self )
189+ }
190+ }
191+ impl <C > AsMut <BitSlice <C , $t>> for [ $t]
192+ where C : Cursor {
193+ fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
194+ BitSlice :: from_slice_mut( self )
195+ }
196+ }
197+ impl <C > AsRef <BitSlice <C , $t>> for [ $t]
198+ where C : Cursor {
199+ fn as_ref( & self ) -> & BitSlice <C , $t> {
200+ BitSlice :: from_slice( self )
201+ }
202+ }
203+ impl_bits_for!( ts $t ; n
204+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
205+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
206+ 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 ,
207+ 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
208+ 32
209+ ) ;
210+ ) * } ;
211+ ( ts $t: ty ; n $( $n: expr ) ,* ) => { $(
212+ impl <C > AsMut <BitSlice <C , $t>> for [ $t; $n]
213+ where C : Cursor {
214+ fn as_mut( & mut self ) -> & mut BitSlice <C , $t> {
215+ BitSlice :: from_slice_mut( self )
216+ }
217+ }
218+ impl <C > AsRef <BitSlice <C , $t>> for [ $t; $n]
219+ where C : Cursor {
220+ fn as_ref( & self ) -> & BitSlice <C , $t> {
221+ BitSlice :: from_slice( self )
222+ }
223+ }
256224 ) * } ;
257225}
258226
259- impl_bits_for ! { u8 , u16 , u32 }
227+ impl_bits_for ! [ n
228+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
229+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
230+ 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 ,
231+ 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
232+ 32
233+ ] ;
234+
235+ impl_bits_for ! [ t u8 , u16 , u32 ] ;
260236
261237#[ cfg( target_pointer_width = "64" ) ]
262- impl_bits_for ! { u64 }
238+ impl_bits_for ! [ t u64 ] ;
0 commit comments