|
1 | 1 | use core::alloc::Allocator; |
2 | 2 | #[cfg(not(no_global_oom_handling))] |
3 | 3 | use core::convert; |
4 | | -use core::marker::PhantomData; |
| 4 | +use core::fmt::{self, Debug, Display, Formatter, Pointer}; |
| 5 | +use core::hash::{Hash, Hasher}; |
| 6 | +use core::marker::{PhantomData, Unsize}; |
5 | 7 | #[cfg(not(no_global_oom_handling))] |
6 | 8 | use core::mem::{self, SizedTypeProperties}; |
| 9 | +use core::ops::{CoerceUnsized, DispatchFromDyn}; |
7 | 10 | #[cfg(not(no_global_oom_handling))] |
8 | 11 | use core::ops::{Residual, Try}; |
9 | 12 |
|
| 13 | +use crate::alloc::Global; |
10 | 14 | use crate::raw_rc::RefCounter; |
11 | 15 | use crate::raw_rc::raw_rc::RawRc; |
12 | 16 | #[cfg(not(no_global_oom_handling))] |
@@ -170,3 +174,121 @@ impl<T, A> RawUniqueRc<T, A> { |
170 | 174 | try { map_result(unsafe { RawUniqueRc::from_weak_with_value(allocation, mapped_value) }) } |
171 | 175 | } |
172 | 176 | } |
| 177 | + |
| 178 | +impl<T, A> AsMut<T> for RawUniqueRc<T, A> |
| 179 | +where |
| 180 | + T: ?Sized, |
| 181 | +{ |
| 182 | + fn as_mut(&mut self) -> &mut T { |
| 183 | + unsafe { self.weak.as_ptr().as_mut() } |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +impl<T, A> AsRef<T> for RawUniqueRc<T, A> |
| 188 | +where |
| 189 | + T: ?Sized, |
| 190 | +{ |
| 191 | + fn as_ref(&self) -> &T { |
| 192 | + unsafe { self.weak.as_ptr().as_ref() } |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | +impl<T, U, A> CoerceUnsized<RawUniqueRc<U, A>> for RawUniqueRc<T, A> |
| 197 | +where |
| 198 | + T: Unsize<U> + ?Sized, |
| 199 | + U: ?Sized, |
| 200 | + A: Allocator, |
| 201 | +{ |
| 202 | +} |
| 203 | + |
| 204 | +impl<T, A> Debug for RawUniqueRc<T, A> |
| 205 | +where |
| 206 | + T: Debug + ?Sized, |
| 207 | +{ |
| 208 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 209 | + <T as Debug>::fmt(self.as_ref(), f) |
| 210 | + } |
| 211 | +} |
| 212 | + |
| 213 | +impl<T, U> DispatchFromDyn<RawUniqueRc<U, Global>> for RawUniqueRc<T, Global> |
| 214 | +where |
| 215 | + T: Unsize<U> + ?Sized, |
| 216 | + U: ?Sized, |
| 217 | +{ |
| 218 | +} |
| 219 | + |
| 220 | +impl<T, A> Display for RawUniqueRc<T, A> |
| 221 | +where |
| 222 | + T: Display + ?Sized, |
| 223 | +{ |
| 224 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 225 | + <T as Display>::fmt(self.as_ref(), f) |
| 226 | + } |
| 227 | +} |
| 228 | + |
| 229 | +impl<T, A> Eq for RawUniqueRc<T, A> where T: Eq + ?Sized {} |
| 230 | + |
| 231 | +impl<T, A> Hash for RawUniqueRc<T, A> |
| 232 | +where |
| 233 | + T: Hash + ?Sized, |
| 234 | +{ |
| 235 | + fn hash<H: Hasher>(&self, state: &mut H) { |
| 236 | + T::hash(self.as_ref(), state); |
| 237 | + } |
| 238 | +} |
| 239 | + |
| 240 | +impl<T, A> Ord for RawUniqueRc<T, A> |
| 241 | +where |
| 242 | + T: Ord + ?Sized, |
| 243 | +{ |
| 244 | + fn cmp(&self, other: &Self) -> core::cmp::Ordering { |
| 245 | + T::cmp(self.as_ref(), other.as_ref()) |
| 246 | + } |
| 247 | +} |
| 248 | + |
| 249 | +impl<T, A> PartialEq for RawUniqueRc<T, A> |
| 250 | +where |
| 251 | + T: PartialEq + ?Sized, |
| 252 | +{ |
| 253 | + fn eq(&self, other: &Self) -> bool { |
| 254 | + T::eq(self.as_ref(), other.as_ref()) |
| 255 | + } |
| 256 | + |
| 257 | + fn ne(&self, other: &Self) -> bool { |
| 258 | + T::ne(self.as_ref(), other.as_ref()) |
| 259 | + } |
| 260 | +} |
| 261 | + |
| 262 | +impl<T, A> PartialOrd for RawUniqueRc<T, A> |
| 263 | +where |
| 264 | + T: PartialOrd + ?Sized, |
| 265 | +{ |
| 266 | + fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { |
| 267 | + T::partial_cmp(self.as_ref(), other.as_ref()) |
| 268 | + } |
| 269 | + |
| 270 | + fn lt(&self, other: &Self) -> bool { |
| 271 | + T::lt(self.as_ref(), other.as_ref()) |
| 272 | + } |
| 273 | + |
| 274 | + fn le(&self, other: &Self) -> bool { |
| 275 | + T::le(self.as_ref(), other.as_ref()) |
| 276 | + } |
| 277 | + |
| 278 | + fn gt(&self, other: &Self) -> bool { |
| 279 | + T::gt(self.as_ref(), other.as_ref()) |
| 280 | + } |
| 281 | + |
| 282 | + fn ge(&self, other: &Self) -> bool { |
| 283 | + T::ge(self.as_ref(), other.as_ref()) |
| 284 | + } |
| 285 | +} |
| 286 | + |
| 287 | +impl<T, A> Pointer for RawUniqueRc<T, A> |
| 288 | +where |
| 289 | + T: ?Sized, |
| 290 | +{ |
| 291 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 292 | + <&T as Pointer>::fmt(&self.as_ref(), f) |
| 293 | + } |
| 294 | +} |
0 commit comments