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