@@ -257,7 +257,6 @@ impl PySequence {
257257 }
258258}
259259
260- #[ cfg( feature = "const-generics" ) ]
261260impl < ' a , T , const N : usize > FromPyObject < ' a > for [ T ; N ]
262261where
263262 T : FromPyObject < ' a > ,
@@ -273,7 +272,6 @@ where
273272 }
274273}
275274
276- #[ cfg( all( feature = "const-generics" , feature = "nightly" ) ) ]
277275impl < ' source , T , const N : usize > FromPyObject < ' source > for [ T ; N ]
278276where
279277 for < ' a > T : FromPyObject < ' a > + crate :: buffer:: Element ,
@@ -291,59 +289,6 @@ where
291289 }
292290}
293291
294- #[ cfg( not( feature = "const-generics" ) ) ]
295- macro_rules! array_impls {
296- ( $( $N: expr) ,+) => {
297- $(
298- impl <' a, T > FromPyObject <' a> for [ T ; $N]
299- where
300- T : Copy + Default + FromPyObject <' a>,
301- {
302- #[ cfg( not( feature = "nightly" ) ) ]
303- fn extract( obj: & ' a PyAny ) -> PyResult <Self > {
304- let mut array = [ T :: default ( ) ; $N] ;
305- extract_sequence_into_slice( obj, & mut array) ?;
306- Ok ( array)
307- }
308-
309- #[ cfg( feature = "nightly" ) ]
310- default fn extract( obj: & ' a PyAny ) -> PyResult <Self > {
311- let mut array = [ T :: default ( ) ; $N] ;
312- extract_sequence_into_slice( obj, & mut array) ?;
313- Ok ( array)
314- }
315- }
316-
317- #[ cfg( feature = "nightly" ) ]
318- impl <' source, T > FromPyObject <' source> for [ T ; $N]
319- where
320- for <' a> T : Default + FromPyObject <' a> + crate :: buffer:: Element ,
321- {
322- fn extract( obj: & ' source PyAny ) -> PyResult <Self > {
323- let mut array = [ T :: default ( ) ; $N] ;
324- // first try buffer protocol
325- if let Ok ( buf) = crate :: buffer:: PyBuffer :: get( obj) {
326- if buf. dimensions( ) == 1 && buf. copy_to_slice( obj. py( ) , & mut array) . is_ok( ) {
327- buf. release( obj. py( ) ) ;
328- return Ok ( array) ;
329- }
330- buf. release( obj. py( ) ) ;
331- }
332- // fall back to sequence protocol
333- extract_sequence_into_slice( obj, & mut array) ?;
334- Ok ( array)
335- }
336- }
337- ) +
338- }
339- }
340-
341- #[ cfg( not( feature = "const-generics" ) ) ]
342- array_impls ! (
343- 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 ,
344- 26 , 27 , 28 , 29 , 30 , 31 , 32
345- ) ;
346-
347292impl < ' a , T > FromPyObject < ' a > for Vec < T >
348293where
349294 T : FromPyObject < ' a > ,
@@ -379,7 +324,6 @@ where
379324 }
380325}
381326
382- #[ cfg( feature = "const-generics" ) ]
383327fn create_array_from_obj < ' s , T , const N : usize > ( obj : & ' s PyAny ) -> PyResult < [ T ; N ] >
384328where
385329 T : FromPyObject < ' s > ,
@@ -406,23 +350,6 @@ where
406350 Ok ( v)
407351}
408352
409- #[ cfg( not( feature = "const-generics" ) ) ]
410- fn extract_sequence_into_slice < ' s , T > ( obj : & ' s PyAny , slice : & mut [ T ] ) -> PyResult < ( ) >
411- where
412- T : FromPyObject < ' s > ,
413- {
414- let seq = <PySequence as PyTryFrom >:: try_from ( obj) ?;
415- if seq. len ( ) ? as usize != slice. len ( ) {
416- return Err ( exceptions:: PyBufferError :: py_err (
417- "Slice length does not match buffer length." ,
418- ) ) ;
419- }
420- for ( value, item) in slice. iter_mut ( ) . zip ( seq. iter ( ) ?) {
421- * value = item?. extract :: < T > ( ) ?;
422- }
423- Ok ( ( ) )
424- }
425-
426353impl < ' v > PyTryFrom < ' v > for PySequence {
427354 fn try_from < V : Into < & ' v PyAny > > ( value : V ) -> Result < & ' v PySequence , PyDowncastError < ' v > > {
428355 let value = value. into ( ) ;
0 commit comments