Make Vec::leak
a method instead of an associated function.
The reason for `Box::leak` not to be a method (`Deref` to an arbitrary `T` which might have its own, different `leak` method) does not apply.
This commit is contained in:
parent
10c375700c
commit
d8bcf75206
1 changed files with 3 additions and 3 deletions
|
@ -1513,17 +1513,17 @@ impl<T> Vec<T> {
|
||||||
/// #![feature(vec_leak)]
|
/// #![feature(vec_leak)]
|
||||||
///
|
///
|
||||||
/// let x = vec![1, 2, 3];
|
/// let x = vec![1, 2, 3];
|
||||||
/// let static_ref: &'static mut [usize] = Vec::leak(x);
|
/// let static_ref: &'static mut [usize] = x.leak();
|
||||||
/// static_ref[0] += 1;
|
/// static_ref[0] += 1;
|
||||||
/// assert_eq!(static_ref, &[2, 2, 3]);
|
/// assert_eq!(static_ref, &[2, 2, 3]);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "vec_leak", issue = "62195")]
|
#[unstable(feature = "vec_leak", issue = "62195")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T]
|
pub fn leak<'a>(self) -> &'a mut [T]
|
||||||
where
|
where
|
||||||
T: 'a, // Technically not needed, but kept to be explicit.
|
T: 'a, // Technically not needed, but kept to be explicit.
|
||||||
{
|
{
|
||||||
Box::leak(vec.into_boxed_slice())
|
Box::leak(self.into_boxed_slice())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue