Skip to content

Commit edcc5a9

Browse files
committed
UniqueRc: Add more trait impls.
* Support the same formatting as Rc * Add explicit !Send and !Sync impls, to mirror Rc * DispatchFromDyn * borrowing traits and Unpin
1 parent 89b6885 commit edcc5a9

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

Diff for: library/alloc/src/rc.rs

+68-1
Original file line numberDiff line numberDiff line change
@@ -3684,7 +3684,6 @@ fn data_offset_align(align: usize) -> usize {
36843684
/// previous example, `UniqueRc` allows for more flexibility in the construction of cyclic data,
36853685
/// including fallible or async constructors.
36863686
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3687-
#[derive(Debug)]
36883687
pub struct UniqueRc<
36893688
T: ?Sized,
36903689
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
@@ -3694,12 +3693,80 @@ pub struct UniqueRc<
36943693
alloc: A,
36953694
}
36963695

3696+
// Not necessary for correctness since `UniqueRc` contains `NonNull`,
3697+
// but having an explicit negative impl is nice for documentation purposes
3698+
// and results in nicer error messages.
3699+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3700+
impl<T: ?Sized, A: Allocator> !Send for UniqueRc<T, A> {}
3701+
3702+
// Not necessary for correctness since `UniqueRc` contains `NonNull`,
3703+
// but having an explicit negative impl is nice for documentation purposes
3704+
// and results in nicer error messages.
3705+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3706+
impl<T: ?Sized, A: Allocator> !Sync for UniqueRc<T, A> {}
3707+
36973708
#[unstable(feature = "unique_rc_arc", issue = "112566")]
36983709
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<UniqueRc<U, A>>
36993710
for UniqueRc<T, A>
37003711
{
37013712
}
37023713

3714+
//#[unstable(feature = "unique_rc_arc", issue = "112566")]
3715+
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
3716+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<UniqueRc<U>> for UniqueRc<T> {}
3717+
3718+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3719+
impl<T: ?Sized + fmt::Display, A: Allocator> fmt::Display for UniqueRc<T, A> {
3720+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3721+
fmt::Display::fmt(&**self, f)
3722+
}
3723+
}
3724+
3725+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3726+
impl<T: ?Sized + fmt::Debug, A: Allocator> fmt::Debug for UniqueRc<T, A> {
3727+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3728+
fmt::Debug::fmt(&**self, f)
3729+
}
3730+
}
3731+
3732+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3733+
impl<T: ?Sized, A: Allocator> fmt::Pointer for UniqueRc<T, A> {
3734+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3735+
fmt::Pointer::fmt(&(&raw const **self), f)
3736+
}
3737+
}
3738+
3739+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3740+
impl<T: ?Sized, A: Allocator> borrow::Borrow<T> for UniqueRc<T, A> {
3741+
fn borrow(&self) -> &T {
3742+
&**self
3743+
}
3744+
}
3745+
3746+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3747+
impl<T: ?Sized, A: Allocator> borrow::BorrowMut<T> for UniqueRc<T, A> {
3748+
fn borrow_mut(&mut self) -> &mut T {
3749+
&mut **self
3750+
}
3751+
}
3752+
3753+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3754+
impl<T: ?Sized, A: Allocator> AsRef<T> for UniqueRc<T, A> {
3755+
fn as_ref(&self) -> &T {
3756+
&**self
3757+
}
3758+
}
3759+
3760+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3761+
impl<T: ?Sized, A: Allocator> AsMut<T> for UniqueRc<T, A> {
3762+
fn as_mut(&mut self) -> &mut T {
3763+
&mut **self
3764+
}
3765+
}
3766+
3767+
#[unstable(feature = "unique_rc_arc", issue = "112566")]
3768+
impl<T: ?Sized, A: Allocator> Unpin for UniqueRc<T, A> {}
3769+
37033770
// Depends on A = Global
37043771
impl<T> UniqueRc<T> {
37053772
/// Creates a new `UniqueRc`.

0 commit comments

Comments
 (0)