@@ -458,3 +458,65 @@ impl<T, A> RawWeak<T, A> {
458
458
}
459
459
}
460
460
}
461
+
462
+ impl < T , A > RawWeak < [ T ] , A > {
463
+ #[ cfg( not( no_global_oom_handling) ) ]
464
+ fn allocate < F > ( length : usize , allocate_fn : F ) -> Self
465
+ where
466
+ A : Allocator ,
467
+ F : FnOnce ( RcLayout ) -> ( RcValuePointer , A ) ,
468
+ {
469
+ let rc_layout = RcLayout :: new_array :: < T > ( length) ;
470
+ let ( ptr, alloc) = allocate_fn ( rc_layout) ;
471
+
472
+ unsafe {
473
+ Self :: from_raw_parts ( NonNull :: slice_from_raw_parts ( ptr. as_ptr ( ) . cast ( ) , length) , alloc)
474
+ }
475
+ }
476
+
477
+ #[ cfg( not( no_global_oom_handling) ) ]
478
+ fn allocate_in < F > ( length : usize , alloc : A , allocate_fn : F ) -> Self
479
+ where
480
+ A : Allocator ,
481
+ F : FnOnce ( & A , RcLayout ) -> RcValuePointer ,
482
+ {
483
+ let rc_layout = RcLayout :: new_array :: < T > ( length) ;
484
+ let ptr = allocate_fn ( & alloc, rc_layout) ;
485
+
486
+ unsafe {
487
+ Self :: from_raw_parts ( NonNull :: slice_from_raw_parts ( ptr. as_ptr ( ) . cast ( ) , length) , alloc)
488
+ }
489
+ }
490
+
491
+ #[ cfg( not( no_global_oom_handling) ) ]
492
+ pub ( crate ) fn new_uninit_slice < const STRONG_COUNT : usize > ( length : usize ) -> Self
493
+ where
494
+ A : Allocator + Default ,
495
+ {
496
+ Self :: allocate ( length, rc_alloc:: allocate_uninit :: < A , STRONG_COUNT > )
497
+ }
498
+
499
+ #[ cfg( not( no_global_oom_handling) ) ]
500
+ pub ( crate ) fn new_uninit_slice_in < const STRONG_COUNT : usize > ( length : usize , alloc : A ) -> Self
501
+ where
502
+ A : Allocator ,
503
+ {
504
+ Self :: allocate_in ( length, alloc, rc_alloc:: allocate_uninit_in :: < A , STRONG_COUNT > )
505
+ }
506
+
507
+ #[ cfg( not( no_global_oom_handling) ) ]
508
+ pub ( crate ) fn new_zeroed_slice < const STRONG_COUNT : usize > ( length : usize ) -> Self
509
+ where
510
+ A : Allocator + Default ,
511
+ {
512
+ Self :: allocate ( length, rc_alloc:: allocate_zeroed :: < A , STRONG_COUNT > )
513
+ }
514
+
515
+ #[ cfg( not( no_global_oom_handling) ) ]
516
+ pub ( crate ) fn new_zeroed_slice_in < const STRONG_COUNT : usize > ( length : usize , alloc : A ) -> Self
517
+ where
518
+ A : Allocator ,
519
+ {
520
+ Self :: allocate_in ( length, alloc, rc_alloc:: allocate_zeroed_in :: < A , STRONG_COUNT > )
521
+ }
522
+ }
0 commit comments