Skip to content

Commit 99522fc

Browse files
committed
Implement necessary traits for RawWeak
1 parent adddf22 commit 99522fc

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

‎library/alloc/src/raw_rc/raw_weak.rs‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use core::alloc::{AllocError, Allocator};
22
use core::cell::UnsafeCell;
3-
use core::marker::PhantomData;
3+
use core::fmt::{self, Debug, Formatter};
4+
use core::marker::{PhantomData, Unsize};
45
use core::mem;
56
use core::num::NonZeroUsize;
6-
use core::ops::{Deref, DerefMut};
7+
use core::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn};
78
use core::ptr::{self, NonNull};
89

10+
use crate::alloc::Global;
911
use crate::raw_rc::rc_layout::{RcLayout, RcLayoutExt};
1012
use crate::raw_rc::rc_value_pointer::RcValuePointer;
1113
use crate::raw_rc::{RefCounter, RefCounts};
@@ -530,3 +532,35 @@ impl<T, A> RawWeak<[T], A> {
530532
Self::allocate_in(length, alloc, super::allocate_zeroed_in::<A, STRONG_COUNT>)
531533
}
532534
}
535+
536+
impl<T, U, A> CoerceUnsized<RawWeak<U, A>> for RawWeak<T, A>
537+
where
538+
T: Unsize<U> + ?Sized,
539+
U: ?Sized,
540+
{
541+
}
542+
543+
impl<T, A> Debug for RawWeak<T, A>
544+
where
545+
T: ?Sized,
546+
{
547+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
548+
f.write_str("(Weak)")
549+
}
550+
}
551+
552+
impl<T, A> Default for RawWeak<T, A>
553+
where
554+
A: Default,
555+
{
556+
fn default() -> Self {
557+
Self::new_dangling()
558+
}
559+
}
560+
561+
impl<T, U> DispatchFromDyn<RawWeak<U, Global>> for RawWeak<T, Global>
562+
where
563+
T: Unsize<U> + ?Sized,
564+
U: ?Sized,
565+
{
566+
}

0 commit comments

Comments
 (0)