Skip to content

Commit 84a7178

Browse files
committed
Implement necessary traits for RawWeak
1 parent e8fb46c commit 84a7178

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

library/alloc/src/raw_rc/raw_weak.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use core::alloc::{AllocError, Allocator};
22
use core::cell::UnsafeCell;
3+
use core::fmt::{self, Debug, Formatter};
4+
use core::marker::Unsize;
35
use core::mem::{self, DropGuard};
46
use core::num::NonZeroUsize;
7+
use core::ops::{CoerceUnsized, DispatchFromDyn};
58
use core::ptr::{self, NonNull};
69

10+
use crate::alloc::Global;
711
use crate::raw_rc::rc_layout::{RcLayout, RcLayoutExt};
812
use crate::raw_rc::rc_value_pointer::RcValuePointer;
913
use crate::raw_rc::{RefCounter, RefCounts, rc_alloc};
@@ -520,3 +524,35 @@ impl<T, A> RawWeak<[T], A> {
520524
Self::allocate_in(length, alloc, rc_alloc::allocate_zeroed_in::<A, STRONG_COUNT>)
521525
}
522526
}
527+
528+
impl<T, U, A> CoerceUnsized<RawWeak<U, A>> for RawWeak<T, A>
529+
where
530+
T: Unsize<U> + ?Sized,
531+
U: ?Sized,
532+
{
533+
}
534+
535+
impl<T, A> Debug for RawWeak<T, A>
536+
where
537+
T: ?Sized,
538+
{
539+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
540+
f.write_str("(Weak)")
541+
}
542+
}
543+
544+
impl<T, A> Default for RawWeak<T, A>
545+
where
546+
A: Default,
547+
{
548+
fn default() -> Self {
549+
Self::new_dangling()
550+
}
551+
}
552+
553+
impl<T, U> DispatchFromDyn<RawWeak<U, Global>> for RawWeak<T, Global>
554+
where
555+
T: Unsize<U> + ?Sized,
556+
U: ?Sized,
557+
{
558+
}

0 commit comments

Comments
 (0)