|
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))] |
@@ -162,3 +166,121 @@ impl<T, A> RawUniqueRc<T, A> { |
162 | 166 | try { map_result(unsafe { RawUniqueRc::from_weak_with_value(allocation, mapped_value) }) } |
163 | 167 | } |
164 | 168 | } |
| 169 | + |
| 170 | +impl<T, A> AsMut<T> for RawUniqueRc<T, A> |
| 171 | +where |
| 172 | + T: ?Sized, |
| 173 | +{ |
| 174 | + fn as_mut(&mut self) -> &mut T { |
| 175 | + unsafe { self.weak.as_ptr().as_mut() } |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +impl<T, A> AsRef<T> for RawUniqueRc<T, A> |
| 180 | +where |
| 181 | + T: ?Sized, |
| 182 | +{ |
| 183 | + fn as_ref(&self) -> &T { |
| 184 | + unsafe { self.weak.as_ptr().as_ref() } |
| 185 | + } |
| 186 | +} |
| 187 | + |
| 188 | +impl<T, U, A> CoerceUnsized<RawUniqueRc<U, A>> for RawUniqueRc<T, A> |
| 189 | +where |
| 190 | + T: Unsize<U> + ?Sized, |
| 191 | + U: ?Sized, |
| 192 | + A: Allocator, |
| 193 | +{ |
| 194 | +} |
| 195 | + |
| 196 | +impl<T, A> Debug for RawUniqueRc<T, A> |
| 197 | +where |
| 198 | + T: Debug + ?Sized, |
| 199 | +{ |
| 200 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 201 | + <T as Debug>::fmt(self.as_ref(), f) |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +impl<T, U> DispatchFromDyn<RawUniqueRc<U, Global>> for RawUniqueRc<T, Global> |
| 206 | +where |
| 207 | + T: Unsize<U> + ?Sized, |
| 208 | + U: ?Sized, |
| 209 | +{ |
| 210 | +} |
| 211 | + |
| 212 | +impl<T, A> Display for RawUniqueRc<T, A> |
| 213 | +where |
| 214 | + T: Display + ?Sized, |
| 215 | +{ |
| 216 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 217 | + <T as Display>::fmt(self.as_ref(), f) |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +impl<T, A> Eq for RawUniqueRc<T, A> where T: Eq + ?Sized {} |
| 222 | + |
| 223 | +impl<T, A> Hash for RawUniqueRc<T, A> |
| 224 | +where |
| 225 | + T: Hash + ?Sized, |
| 226 | +{ |
| 227 | + fn hash<H: Hasher>(&self, state: &mut H) { |
| 228 | + T::hash(self.as_ref(), state); |
| 229 | + } |
| 230 | +} |
| 231 | + |
| 232 | +impl<T, A> Ord for RawUniqueRc<T, A> |
| 233 | +where |
| 234 | + T: Ord + ?Sized, |
| 235 | +{ |
| 236 | + fn cmp(&self, other: &Self) -> core::cmp::Ordering { |
| 237 | + T::cmp(self.as_ref(), other.as_ref()) |
| 238 | + } |
| 239 | +} |
| 240 | + |
| 241 | +impl<T, A> PartialEq for RawUniqueRc<T, A> |
| 242 | +where |
| 243 | + T: PartialEq + ?Sized, |
| 244 | +{ |
| 245 | + fn eq(&self, other: &Self) -> bool { |
| 246 | + T::eq(self.as_ref(), other.as_ref()) |
| 247 | + } |
| 248 | + |
| 249 | + fn ne(&self, other: &Self) -> bool { |
| 250 | + T::ne(self.as_ref(), other.as_ref()) |
| 251 | + } |
| 252 | +} |
| 253 | + |
| 254 | +impl<T, A> PartialOrd for RawUniqueRc<T, A> |
| 255 | +where |
| 256 | + T: PartialOrd + ?Sized, |
| 257 | +{ |
| 258 | + fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { |
| 259 | + T::partial_cmp(self.as_ref(), other.as_ref()) |
| 260 | + } |
| 261 | + |
| 262 | + fn lt(&self, other: &Self) -> bool { |
| 263 | + T::lt(self.as_ref(), other.as_ref()) |
| 264 | + } |
| 265 | + |
| 266 | + fn le(&self, other: &Self) -> bool { |
| 267 | + T::le(self.as_ref(), other.as_ref()) |
| 268 | + } |
| 269 | + |
| 270 | + fn gt(&self, other: &Self) -> bool { |
| 271 | + T::gt(self.as_ref(), other.as_ref()) |
| 272 | + } |
| 273 | + |
| 274 | + fn ge(&self, other: &Self) -> bool { |
| 275 | + T::ge(self.as_ref(), other.as_ref()) |
| 276 | + } |
| 277 | +} |
| 278 | + |
| 279 | +impl<T, A> Pointer for RawUniqueRc<T, A> |
| 280 | +where |
| 281 | + T: ?Sized, |
| 282 | +{ |
| 283 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 284 | + <&T as Pointer>::fmt(&self.as_ref(), f) |
| 285 | + } |
| 286 | +} |
0 commit comments