Skip to content

Commit 0cfa9b9

Browse files
committed
Add fn allocator to all Rc/Arc/Weak.
1 parent d157355 commit 0cfa9b9

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

library/alloc/src/rc.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -660,16 +660,6 @@ impl<T> Rc<T> {
660660
}
661661

662662
impl<T, A: Allocator> Rc<T, A> {
663-
/// Returns a reference to the underlying allocator.
664-
///
665-
/// Note: this is an associated function, which means that you have
666-
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
667-
/// is so that there is no conflict with a method on the inner type.
668-
#[inline]
669-
#[unstable(feature = "allocator_api", issue = "32838")]
670-
pub fn allocator(this: &Self) -> &A {
671-
&this.alloc
672-
}
673663
/// Constructs a new `Rc` in the provided allocator.
674664
///
675665
/// # Examples
@@ -1283,6 +1273,17 @@ impl<T: ?Sized> Rc<T> {
12831273
}
12841274

12851275
impl<T: ?Sized, A: Allocator> Rc<T, A> {
1276+
/// Returns a reference to the underlying allocator.
1277+
///
1278+
/// Note: this is an associated function, which means that you have
1279+
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
1280+
/// is so that there is no conflict with a method on the inner type.
1281+
#[inline]
1282+
#[unstable(feature = "allocator_api", issue = "32838")]
1283+
pub fn allocator(this: &Self) -> &A {
1284+
&this.alloc
1285+
}
1286+
12861287
/// Consumes the `Rc`, returning the wrapped pointer.
12871288
///
12881289
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
@@ -2861,6 +2862,13 @@ impl<T: ?Sized> Weak<T> {
28612862
}
28622863

28632864
impl<T: ?Sized, A: Allocator> Weak<T, A> {
2865+
/// Returns a reference to the underlying allocator.
2866+
#[inline]
2867+
#[unstable(feature = "allocator_api", issue = "32838")]
2868+
pub fn allocator(&self) -> &A {
2869+
&self.alloc
2870+
}
2871+
28642872
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
28652873
///
28662874
/// The pointer is valid only if there are some strong references. The pointer may be dangling,

library/alloc/src/sync.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -677,16 +677,6 @@ impl<T> Arc<T> {
677677
}
678678

679679
impl<T, A: Allocator> Arc<T, A> {
680-
/// Returns a reference to the underlying allocator.
681-
///
682-
/// Note: this is an associated function, which means that you have
683-
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
684-
/// is so that there is no conflict with a method on the inner type.
685-
#[inline]
686-
#[unstable(feature = "allocator_api", issue = "32838")]
687-
pub fn allocator(this: &Self) -> &A {
688-
&this.alloc
689-
}
690680
/// Constructs a new `Arc<T>` in the provided allocator.
691681
///
692682
/// # Examples
@@ -1433,6 +1423,17 @@ impl<T: ?Sized> Arc<T> {
14331423
}
14341424

14351425
impl<T: ?Sized, A: Allocator> Arc<T, A> {
1426+
/// Returns a reference to the underlying allocator.
1427+
///
1428+
/// Note: this is an associated function, which means that you have
1429+
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
1430+
/// is so that there is no conflict with a method on the inner type.
1431+
#[inline]
1432+
#[unstable(feature = "allocator_api", issue = "32838")]
1433+
pub fn allocator(this: &Self) -> &A {
1434+
&this.alloc
1435+
}
1436+
14361437
/// Consumes the `Arc`, returning the wrapped pointer.
14371438
///
14381439
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
@@ -2619,6 +2620,13 @@ impl<T: ?Sized> Weak<T> {
26192620
}
26202621

26212622
impl<T: ?Sized, A: Allocator> Weak<T, A> {
2623+
/// Returns a reference to the underlying allocator.
2624+
#[inline]
2625+
#[unstable(feature = "allocator_api", issue = "32838")]
2626+
pub fn allocator(&self) -> &A {
2627+
&self.alloc
2628+
}
2629+
26222630
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
26232631
///
26242632
/// The pointer is valid only if there are some strong references. The pointer may be dangling,

0 commit comments

Comments
 (0)