|
1 | 1 | use core::alloc::{AllocError, Allocator}; |
2 | 2 | use core::cell::UnsafeCell; |
| 3 | +use core::fmt::{self, Debug, Formatter}; |
| 4 | +use core::marker::Unsize; |
3 | 5 | use core::mem::{self, DropGuard}; |
4 | 6 | use core::num::NonZeroUsize; |
| 7 | +use core::ops::{CoerceUnsized, DispatchFromDyn}; |
5 | 8 | use core::ptr::{self, NonNull}; |
6 | 9 |
|
| 10 | +use crate::alloc::Global; |
7 | 11 | use crate::raw_rc::rc_layout::{RcLayout, RcLayoutExt}; |
8 | 12 | use crate::raw_rc::rc_value_pointer::RcValuePointer; |
9 | 13 | use crate::raw_rc::{RefCounter, RefCounts, rc_alloc}; |
@@ -435,6 +439,38 @@ impl<T, A> RawWeak<[T], A> { |
435 | 439 | } |
436 | 440 | } |
437 | 441 |
|
| 442 | +impl<T, U, A> CoerceUnsized<RawWeak<U, A>> for RawWeak<T, A> |
| 443 | +where |
| 444 | + T: Unsize<U> + ?Sized, |
| 445 | + U: ?Sized, |
| 446 | +{ |
| 447 | +} |
| 448 | + |
| 449 | +impl<T, A> Debug for RawWeak<T, A> |
| 450 | +where |
| 451 | + T: ?Sized, |
| 452 | +{ |
| 453 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 454 | + f.write_str("(Weak)") |
| 455 | + } |
| 456 | +} |
| 457 | + |
| 458 | +impl<T, A> Default for RawWeak<T, A> |
| 459 | +where |
| 460 | + A: Default, |
| 461 | +{ |
| 462 | + fn default() -> Self { |
| 463 | + Self::new_dangling() |
| 464 | + } |
| 465 | +} |
| 466 | + |
| 467 | +impl<T, U> DispatchFromDyn<RawWeak<U, Global>> for RawWeak<T, Global> |
| 468 | +where |
| 469 | + T: Unsize<U> + ?Sized, |
| 470 | + U: ?Sized, |
| 471 | +{ |
| 472 | +} |
| 473 | + |
438 | 474 | // We choose `NonZeroUsize::MAX` as the address for dangling weak pointers because: |
439 | 475 | // |
440 | 476 | // - It does not point to any object that is stored inside a reference-counted allocation. Because |
|
0 commit comments