Split the Deref implementation for drm::Device by context: - Device<T> (Normal) dereferences to T::Data. - Device<T, Registered> dereferences to Device<T> (Normal).
Unified · Split
| @@ -79,6 +79,9 @@ macro_rules! drm_legacy_fields { · 78 unmodified lines | ||
| 79 | 79 | /// - [`Normal`]: The general-purpose, reference-counted context. A [`Device`] in this context may |
| 80 | 80 | /// or may not be registered with userspace. |
| 81 | 81 | /// - [`Registered`]: The device has been registered with userspace at some point. |
| 82 | +/// | |
| 83 | +/// `Device<T, Registered>` dereferences to `Device<T>` ([`Normal`]), so any method available on a | |
| 84 | +/// [`Normal`] device is also available on a [`Registered`] one. | |
| 82 | 85 | pub trait DeviceContext: Sealed + Send + Sync + 'static {} |
| 83 | 86 | |
| 84 | 87 | /// The general-purpose, reference-counted [`DeviceContext`]. |
| @@ -320,7 +323,7 @@ impl<T: drm::Driver, C: DeviceContext> Device<T, C> { · 235 unmodified lines | ||
| 320 | 323 | } |
| 321 | 324 | } |
| 322 | 325 | |
| 323 | −impl<T: drm::Driver, C: DeviceContext> Deref for Device<T, C> { | |
| 326 | +impl<T: drm::Driver> Deref for Device<T> { | |
| 324 | 327 | type Target = T::Data; |
| 325 | 328 | |
| 326 | 329 | fn deref(&self) -> &Self::Target { |
| @@ -328,6 +331,17 @@ impl<T: drm::Driver, C: DeviceContext> Deref for Device<T, C> { · 1 unmodified line | ||
| 328 | 331 | } |
| 329 | 332 | } |
| 330 | 333 | |
| 334 | +impl<T: drm::Driver> Deref for Device<T, Registered> { | |
| 335 | + type Target = Device<T>; | |
| 336 | + | |
| 337 | + #[inline] | |
| 338 | + fn deref(&self) -> &Self::Target { | |
| 339 | + // SAFETY: The caller holds a `Device<T, Registered>`, which guarantees all invariants | |
| 340 | + // of the weaker `Normal` context. | |
| 341 | + unsafe { self.assume_ctx() } | |
| 342 | + } | |
| 343 | +} | |
| 344 | + | |
| 331 | 345 | // SAFETY: DRM device objects are always reference counted and the get/put functions |
| 332 | 346 | // satisfy the requirements. |
| 333 | 347 | unsafe impl<T: drm::Driver> AlwaysRefCounted for Device<T> { |