@@ -1000,6 +1000,44 @@ impl<T: Copy, A: Allocator> SpecCloneIntoVec<T, A> for [T] {
1000
1000
}
1001
1001
}
1002
1002
1003
+ /// Coallocation-aware version of `SpecCloneIntoVec`.
1004
+ #[ cfg( not( no_global_oom_handling) ) ]
1005
+ #[ allow( unused_braces) ]
1006
+ pub ( crate ) trait SpecCloneIntoVecCo < T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref >
1007
+ where [ ( ) ; { crate :: meta_num_slots!( A , CO_ALLOC_PREF ) } ] : ,
1008
+ {
1009
+ fn clone_into_co ( & self , target : & mut Vec < T , A , CO_ALLOC_PREF > ) ;
1010
+ }
1011
+
1012
+ #[ cfg( not( no_global_oom_handling) ) ]
1013
+ #[ allow( unused_braces) ]
1014
+ impl < T : Clone , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > SpecCloneIntoVecCo < T , A , CO_ALLOC_PREF > for [ T ]
1015
+ where [ ( ) ; { crate :: meta_num_slots!( A , CO_ALLOC_PREF ) } ] : , {
1016
+ default fn clone_into_co ( & self , target : & mut Vec < T , A , CO_ALLOC_PREF > ) {
1017
+ // drop anything in target that will not be overwritten
1018
+ target. truncate ( self . len ( ) ) ;
1019
+
1020
+ // target.len <= self.len due to the truncate above, so the
1021
+ // slices here are always in-bounds.
1022
+ let ( init, tail) = self . split_at ( target. len ( ) ) ;
1023
+
1024
+ // reuse the contained values' allocations/resources.
1025
+ target. clone_from_slice ( init) ;
1026
+ target. extend_from_slice ( tail) ;
1027
+ }
1028
+ }
1029
+
1030
+ #[ cfg( not( no_global_oom_handling) ) ]
1031
+ #[ allow( unused_braces) ]
1032
+ impl < T : Copy , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > SpecCloneIntoVecCo < T , A , CO_ALLOC_PREF > for [ T ]
1033
+ where [ ( ) ; { crate :: meta_num_slots!( A , CO_ALLOC_PREF ) } ] : , {
1034
+ fn clone_into_co ( & self , target : & mut Vec < T , A , CO_ALLOC_PREF > ) {
1035
+ target. clear ( ) ;
1036
+ target. extend_from_slice ( self ) ;
1037
+ }
1038
+ }
1039
+
1040
+
1003
1041
#[ cfg( not( no_global_oom_handling) ) ]
1004
1042
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1005
1043
impl < T : Clone > ToOwned for [ T ] {
0 commit comments