@@ -401,7 +401,7 @@ impl<T> Vec<T> {
401
401
#[ inline]
402
402
#[ must_use]
403
403
pub fn with_capacity ( capacity : usize ) -> Self {
404
- Self :: with_capacity_in ( capacity, Global )
404
+ Self :: with_capacity_in ( capacity, & Global )
405
405
}
406
406
407
407
/// Creates a `Vec<T>` directly from the raw components of another vector.
@@ -488,12 +488,12 @@ impl<T, A: DeallocRef> Vec<T, A> {
488
488
/// * if the requested capacity exceeds `usize::MAX` bytes.
489
489
/// * on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
490
490
#[ inline]
491
- pub fn with_capacity_in ( capacity : usize , a : A ) -> Self
491
+ pub fn with_capacity_in ( capacity : usize , a : & A ) -> Self
492
492
where
493
493
A : AllocRef ,
494
494
{
495
495
Self {
496
- buf : RawVec :: with_capacity_in ( capacity, & a) ,
496
+ buf : RawVec :: with_capacity_in ( capacity, a) ,
497
497
len : 0 ,
498
498
}
499
499
}
@@ -2024,11 +2024,11 @@ impl<T: PartialEq, A: DeallocRef> Vec<T, A> {
2024
2024
2025
2025
#[ doc( hidden) ]
2026
2026
pub fn from_elem < T : Clone > ( elem : T , n : usize ) -> Vec < T > {
2027
- from_elem_in ( elem, n, Global )
2027
+ from_elem_in ( elem, n, & Global )
2028
2028
}
2029
2029
2030
2030
#[ doc( hidden) ]
2031
- pub fn from_elem_in < T : Clone , A > ( elem : T , n : usize , a : A ) -> Vec < T , A >
2031
+ pub fn from_elem_in < T : Clone , A > ( elem : T , n : usize , a : & A ) -> Vec < T , A >
2032
2032
where
2033
2033
A : ReallocRef ,
2034
2034
{
@@ -2043,23 +2043,24 @@ where
2043
2043
pub fn try_from_elem_in < T : Clone , A : ReallocRef > (
2044
2044
elem : T ,
2045
2045
n : usize ,
2046
- a : A ,
2046
+ a : & A ,
2047
2047
) -> Result < Vec < T , A > , CollectionAllocErr < A > > {
2048
2048
<T as SpecFromElem < A > >:: try_from_elem_in ( elem, n, a)
2049
2049
}
2050
2050
2051
2051
// Specialization trait used for Vec::from_elem
2052
2052
trait SpecFromElem < A : AllocRef > : Sized {
2053
- fn try_from_elem_in ( elem : Self , n : usize , a : A ) -> Result < Vec < Self , A > , CollectionAllocErr < A > > ;
2053
+ fn try_from_elem_in ( elem : Self , n : usize , a : & A )
2054
+ -> Result < Vec < Self , A > , CollectionAllocErr < A > > ;
2054
2055
}
2055
2056
2056
2057
impl < T : Clone , A : ReallocRef > SpecFromElem < A > for T {
2057
2058
default fn try_from_elem_in (
2058
2059
elem : Self ,
2059
2060
n : usize ,
2060
- a : A ,
2061
+ a : & A ,
2061
2062
) -> Result < Vec < Self , A > , CollectionAllocErr < A > > {
2062
- let mut v = Vec :: try_with_capacity_in ( n, & a) ?;
2063
+ let mut v = Vec :: try_with_capacity_in ( n, a) ?;
2063
2064
v. try_extend_with ( n, ExtendElement ( elem) ) ?;
2064
2065
Ok ( v)
2065
2066
}
@@ -2068,15 +2069,19 @@ impl<T: Clone, A: ReallocRef> SpecFromElem<A> for T {
2068
2069
#[ allow( clippy:: use_self) ]
2069
2070
impl < A : ReallocRef > SpecFromElem < A > for u8 {
2070
2071
#[ inline]
2071
- fn try_from_elem_in ( elem : Self , n : usize , a : A ) -> Result < Vec < Self , A > , CollectionAllocErr < A > > {
2072
+ fn try_from_elem_in (
2073
+ elem : Self ,
2074
+ n : usize ,
2075
+ a : & A ,
2076
+ ) -> Result < Vec < Self , A > , CollectionAllocErr < A > > {
2072
2077
if elem == 0 {
2073
2078
return Ok ( Vec {
2074
- buf : RawVec :: try_with_capacity_zeroed_in ( n, & a) ?,
2079
+ buf : RawVec :: try_with_capacity_zeroed_in ( n, a) ?,
2075
2080
len : n,
2076
2081
} ) ;
2077
2082
}
2078
2083
unsafe {
2079
- let mut v = Vec :: try_with_capacity_in ( n, & a) ?;
2084
+ let mut v = Vec :: try_with_capacity_in ( n, a) ?;
2080
2085
ptr:: write_bytes ( v. as_mut_ptr ( ) , elem, n) ;
2081
2086
v. set_len ( n) ;
2082
2087
Ok ( v)
@@ -2086,14 +2091,18 @@ impl<A: ReallocRef> SpecFromElem<A> for u8 {
2086
2091
2087
2092
impl < T : Clone + IsZero , A : ReallocRef > SpecFromElem < A > for T {
2088
2093
#[ inline]
2089
- fn try_from_elem_in ( elem : Self , n : usize , a : A ) -> Result < Vec < Self , A > , CollectionAllocErr < A > > {
2094
+ fn try_from_elem_in (
2095
+ elem : Self ,
2096
+ n : usize ,
2097
+ a : & A ,
2098
+ ) -> Result < Vec < Self , A > , CollectionAllocErr < A > > {
2090
2099
if elem. is_zero ( ) {
2091
2100
return Ok ( Vec {
2092
- buf : RawVec :: try_with_capacity_zeroed_in ( n, & a) ?,
2101
+ buf : RawVec :: try_with_capacity_zeroed_in ( n, a) ?,
2093
2102
len : n,
2094
2103
} ) ;
2095
2104
}
2096
- let mut v = Vec :: try_with_capacity_in ( n, & a) ?;
2105
+ let mut v = Vec :: try_with_capacity_in ( n, a) ?;
2097
2106
v. try_extend_with ( n, ExtendElement ( elem) ) ?;
2098
2107
Ok ( v)
2099
2108
}
@@ -2201,7 +2210,7 @@ impl<T: Clone, A: AllocRef, B: AllocRef> CloneIn<B> for Vec<T, A> {
2201
2210
type Cloned = Vec < T , B > ;
2202
2211
2203
2212
fn clone_in ( & self , a : B ) -> Self :: Cloned {
2204
- let mut v = Vec :: with_capacity_in ( self . len ( ) , a) ;
2213
+ let mut v = Vec :: with_capacity_in ( self . len ( ) , & a) ;
2205
2214
2206
2215
self . iter ( )
2207
2216
. cloned ( )
0 commit comments