Rollup merge of #124980 - zachs18:rc-allocator, r=Amanieu
Generalize `fn allocator` for Rc/Arc. Split out from #119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. `````@rustbot````` label +A-allocators
This commit is contained in:
commit
65ea92d4a1
2 changed files with 36 additions and 20 deletions
|
@ -665,16 +665,6 @@ impl<T> Rc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, A: Allocator> Rc<T, A> {
|
impl<T, A: Allocator> Rc<T, A> {
|
||||||
/// Returns a reference to the underlying allocator.
|
|
||||||
///
|
|
||||||
/// Note: this is an associated function, which means that you have
|
|
||||||
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
|
|
||||||
/// is so that there is no conflict with a method on the inner type.
|
|
||||||
#[inline]
|
|
||||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
|
||||||
pub fn allocator(this: &Self) -> &A {
|
|
||||||
&this.alloc
|
|
||||||
}
|
|
||||||
/// Constructs a new `Rc` in the provided allocator.
|
/// Constructs a new `Rc` in the provided allocator.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -1331,6 +1321,17 @@ impl<T: ?Sized> Rc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized, A: Allocator> Rc<T, A> {
|
impl<T: ?Sized, A: Allocator> Rc<T, A> {
|
||||||
|
/// Returns a reference to the underlying allocator.
|
||||||
|
///
|
||||||
|
/// Note: this is an associated function, which means that you have
|
||||||
|
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
|
||||||
|
/// is so that there is no conflict with a method on the inner type.
|
||||||
|
#[inline]
|
||||||
|
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||||
|
pub fn allocator(this: &Self) -> &A {
|
||||||
|
&this.alloc
|
||||||
|
}
|
||||||
|
|
||||||
/// Consumes the `Rc`, returning the wrapped pointer.
|
/// Consumes the `Rc`, returning the wrapped pointer.
|
||||||
///
|
///
|
||||||
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
|
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
|
||||||
|
@ -2994,6 +2995,13 @@ impl<T: ?Sized> Weak<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized, A: Allocator> Weak<T, A> {
|
impl<T: ?Sized, A: Allocator> Weak<T, A> {
|
||||||
|
/// Returns a reference to the underlying allocator.
|
||||||
|
#[inline]
|
||||||
|
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||||
|
pub fn allocator(&self) -> &A {
|
||||||
|
&self.alloc
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
|
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
|
||||||
///
|
///
|
||||||
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
|
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
|
||||||
|
|
|
@ -677,16 +677,6 @@ impl<T> Arc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, A: Allocator> Arc<T, A> {
|
impl<T, A: Allocator> Arc<T, A> {
|
||||||
/// Returns a reference to the underlying allocator.
|
|
||||||
///
|
|
||||||
/// Note: this is an associated function, which means that you have
|
|
||||||
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
|
|
||||||
/// is so that there is no conflict with a method on the inner type.
|
|
||||||
#[inline]
|
|
||||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
|
||||||
pub fn allocator(this: &Self) -> &A {
|
|
||||||
&this.alloc
|
|
||||||
}
|
|
||||||
/// Constructs a new `Arc<T>` in the provided allocator.
|
/// Constructs a new `Arc<T>` in the provided allocator.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -1470,6 +1460,17 @@ impl<T: ?Sized> Arc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized, A: Allocator> Arc<T, A> {
|
impl<T: ?Sized, A: Allocator> Arc<T, A> {
|
||||||
|
/// Returns a reference to the underlying allocator.
|
||||||
|
///
|
||||||
|
/// Note: this is an associated function, which means that you have
|
||||||
|
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
|
||||||
|
/// is so that there is no conflict with a method on the inner type.
|
||||||
|
#[inline]
|
||||||
|
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||||
|
pub fn allocator(this: &Self) -> &A {
|
||||||
|
&this.alloc
|
||||||
|
}
|
||||||
|
|
||||||
/// Consumes the `Arc`, returning the wrapped pointer.
|
/// Consumes the `Arc`, returning the wrapped pointer.
|
||||||
///
|
///
|
||||||
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
|
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
|
||||||
|
@ -2715,6 +2716,13 @@ impl<T: ?Sized> Weak<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized, A: Allocator> Weak<T, A> {
|
impl<T: ?Sized, A: Allocator> Weak<T, A> {
|
||||||
|
/// Returns a reference to the underlying allocator.
|
||||||
|
#[inline]
|
||||||
|
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||||
|
pub fn allocator(&self) -> &A {
|
||||||
|
&self.alloc
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
|
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
|
||||||
///
|
///
|
||||||
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
|
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue