Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1ad634

Browse files
committed
Add fn allocator method to rc/sync::Weak. Relax Rc<T>/Arc<T>::allocator to allow unsized T.
1 parent6a19a87 commita1ad634

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
@@ -661,16 +661,6 @@ impl<T> Rc<T> {
661661
}
662662

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

13351325
impl<T: ?Sized,A:Allocator>Rc<T,A>{
1326+
/// Returns a reference to the underlying allocator.
1327+
///
1328+
/// Note: this is an associated function, which means that you have
1329+
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
1330+
/// is so that there is no conflict with a method on the inner type.
1331+
#[inline]
1332+
#[unstable(feature ="allocator_api", issue ="32838")]
1333+
pubfnallocator(this:&Self) ->&A{
1334+
&this.alloc
1335+
}
1336+
13361337
/// Consumes the `Rc`, returning the wrapped pointer.
13371338
///
13381339
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
@@ -2923,6 +2924,13 @@ impl<T: ?Sized> Weak<T> {
29232924
}
29242925

29252926
impl<T: ?Sized,A:Allocator>Weak<T,A>{
2927+
/// Returns a reference to the underlying allocator.
2928+
#[inline]
2929+
#[unstable(feature ="allocator_api", issue ="32838")]
2930+
pubfnallocator(&self) ->&A{
2931+
&self.alloc
2932+
}
2933+
29262934
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
29272935
///
29282936
/// 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
@@ -683,16 +683,6 @@ impl<T> Arc<T> {
683683
}
684684

685685
impl<T,A:Allocator>Arc<T,A>{
686-
/// Returns a reference to the underlying allocator.
687-
///
688-
/// Note: this is an associated function, which means that you have
689-
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
690-
/// is so that there is no conflict with a method on the inner type.
691-
#[inline]
692-
#[unstable(feature ="allocator_api", issue ="32838")]
693-
pubfnallocator(this:&Self) ->&A{
694-
&this.alloc
695-
}
696686
/// Constructs a new `Arc<T>` in the provided allocator.
697687
///
698688
/// # Examples
@@ -1473,6 +1463,17 @@ impl<T: ?Sized> Arc<T> {
14731463
}
14741464

14751465
impl<T: ?Sized,A:Allocator>Arc<T,A>{
1466+
/// Returns a reference to the underlying allocator.
1467+
///
1468+
/// Note: this is an associated function, which means that you have
1469+
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
1470+
/// is so that there is no conflict with a method on the inner type.
1471+
#[inline]
1472+
#[unstable(feature ="allocator_api", issue ="32838")]
1473+
pubfnallocator(this:&Self) ->&A{
1474+
&this.alloc
1475+
}
1476+
14761477
/// Consumes the `Arc`, returning the wrapped pointer.
14771478
///
14781479
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
@@ -2661,6 +2662,13 @@ impl<T: ?Sized> Weak<T> {
26612662
}
26622663

26632664
impl<T: ?Sized,A:Allocator>Weak<T,A>{
2665+
/// Returns a reference to the underlying allocator.
2666+
#[inline]
2667+
#[unstable(feature ="allocator_api", issue ="32838")]
2668+
pubfnallocator(&self) ->&A{
2669+
&self.alloc
2670+
}
2671+
26642672
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
26652673
///
26662674
/// The pointer is valid only if there are some strong references. The pointer may be dangling,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp