mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Auto merge of #74605 - rust-lang:vec-leak, r=Amanieu
Stabilize Vec::leak as a method Closes https://github.com/rust-lang/rust/issues/62195 The signature is changed to a method rather than an associated function: ```diff -pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T] +pub fn leak<'a>(self) -> &'a mut [T] ``` 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:
commit
5ef872f961
@ -1510,20 +1510,18 @@ impl<T> Vec<T> {
|
||||
/// Simple usage:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(vec_leak)]
|
||||
///
|
||||
/// 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;
|
||||
/// assert_eq!(static_ref, &[2, 2, 3]);
|
||||
/// ```
|
||||
#[unstable(feature = "vec_leak", issue = "62195")]
|
||||
#[stable(feature = "vec_leak", since = "1.47.0")]
|
||||
#[inline]
|
||||
pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T]
|
||||
pub fn leak<'a>(self) -> &'a mut [T]
|
||||
where
|
||||
T: 'a, // Technically not needed, but kept to be explicit.
|
||||
{
|
||||
Box::leak(vec.into_boxed_slice())
|
||||
Box::leak(self.into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user