Skip to content

Commit

Permalink
Add fn sync::Weak::allocator, remove A: Clone bound on Arc::unwrap_or…
Browse files Browse the repository at this point in the history
…_clone and From<Vec<T, A>> for Arc<[T], A>
  • Loading branch information
zachs18 committed Feb 19, 2024
1 parent 8cb474e commit c3136d9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,9 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> {
// either unique to begin with, or became one upon cloning the contents.
unsafe { Self::get_mut_unchecked(this) }
}
}

impl<T: Clone, A: Allocator> Arc<T, A> {
/// If we have the only reference to `T` then unwrap it. Otherwise, clone `T` and return the
/// clone.
///
Expand Down Expand Up @@ -2675,6 +2677,13 @@ impl<T: ?Sized> Weak<T> {
}

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>`.
///
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
Expand Down Expand Up @@ -3479,7 +3488,7 @@ impl<T: ?Sized, A: Allocator> From<Box<T, A>> for Arc<T, A> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "shared_from_slice", since = "1.21.0")]
impl<T, A: Allocator + Clone> From<Vec<T, A>> for Arc<[T], A> {
impl<T, A: Allocator> From<Vec<T, A>> for Arc<[T], A> {
/// Allocate a reference-counted slice and move `v`'s items into it.
///
/// # Example
Expand Down

0 comments on commit c3136d9

Please sign in to comment.