1
+ use crate :: claim:: Claim ;
1
2
use crate :: try_clone:: TryClone ;
2
3
use alloc:: alloc:: Allocator ;
3
4
use alloc:: collections:: TryReserveError ;
@@ -147,7 +148,7 @@ impl<T, A: Allocator> Vec<T, A> {
147
148
}
148
149
}
149
150
150
- impl < T : Clone , A : Allocator > Vec < T , A > {
151
+ impl < T : Claim , A : Allocator > Vec < T , A > {
151
152
#[ inline]
152
153
pub fn extend_from_slice ( & mut self , slice : & [ T ] ) -> Result < ( ) , TryReserveError > {
153
154
self . reserve ( slice. len ( ) ) ?;
@@ -186,7 +187,7 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
186
187
}
187
188
}
188
189
189
- impl < T : Copy , A : Allocator + Clone > TryClone for Vec < T , A > {
190
+ impl < T : Claim , A : Allocator + Claim > TryClone for Vec < T , A > {
190
191
type Error = TryReserveError ;
191
192
192
193
fn try_clone ( & self ) -> Result < Self , Self :: Error > {
@@ -288,6 +289,7 @@ impl<T, A: Allocator> AsMut<[T]> for Vec<T, A> {
288
289
#[ cfg( test) ]
289
290
mod tests {
290
291
use super :: * ;
292
+ use crate :: claim:: Claim ;
291
293
use alloc:: alloc:: Global ;
292
294
use alloc:: boxed:: Box ;
293
295
use alloc:: collections:: TryReserveError ;
@@ -303,6 +305,8 @@ mod tests {
303
305
in_use : Arc < AtomicUsize > ,
304
306
}
305
307
308
+ impl Claim for WatermarkAllocator { }
309
+
306
310
impl WatermarkAllocator {
307
311
pub ( crate ) fn in_use ( & self ) -> usize {
308
312
self . in_use . load ( Ordering :: SeqCst )
@@ -496,15 +500,17 @@ mod tests {
496
500
assert_eq ! ( vec[ 3 ] , 4 ) ;
497
501
}
498
502
499
- /// A type that implements `Clone` but not `Copy`.
503
+ /// A type that implements `Clone` and `Claim`, but not `Copy`.
500
504
#[ derive( Clone , Eq , PartialEq ) ]
501
- struct Cloneable ( i32 ) ;
505
+ struct Claimable ( i32 ) ;
506
+
507
+ impl Claim for Claimable { }
502
508
503
509
#[ test]
504
510
fn test_extend_from_slice_clone ( ) {
505
511
let wma = WatermarkAllocator :: new ( 32 ) ;
506
512
let mut vec = Vec :: new_in ( wma) ;
507
- vec. extend_from_slice ( & [ Cloneable ( 1 ) , Cloneable ( 2 ) , Cloneable ( 3 ) , Cloneable ( 4 ) ] )
513
+ vec. extend_from_slice ( & [ Claimable ( 1 ) , Claimable ( 2 ) , Claimable ( 3 ) , Claimable ( 4 ) ] )
508
514
. unwrap ( ) ;
509
515
}
510
516
@@ -783,12 +789,12 @@ mod tests {
783
789
}
784
790
}
785
791
786
- fn get_first_elem_vec < T : Clone , A : Allocator > ( vec : impl AsRef < Vec < T , A > > ) -> T {
792
+ fn get_first_elem_vec < T : Claim , A : Allocator > ( vec : impl AsRef < Vec < T , A > > ) -> T {
787
793
let vec = vec. as_ref ( ) ;
788
794
vec. first ( ) . unwrap ( ) . clone ( )
789
795
}
790
796
791
- fn get_first_elem_slice < T : Clone > ( slice : impl AsRef < [ T ] > ) -> T {
797
+ fn get_first_elem_slice < T : Claim > ( slice : impl AsRef < [ T ] > ) -> T {
792
798
let vec = slice. as_ref ( ) ;
793
799
vec. first ( ) . unwrap ( ) . clone ( )
794
800
}
0 commit comments