@@ -463,90 +463,7 @@ where
463
463
impl < T : ObjectType > ObjectDeref for & T { }
464
464
impl < T : ObjectType > ObjectCast for & T { }
465
465
466
- /// Trait for mutable type casting operations in the QOM hierarchy.
467
- ///
468
- /// This trait provides the mutable counterparts to [`ObjectCast`]'s conversion
469
- /// functions. Unlike `ObjectCast`, this trait returns `Result` for fallible
470
- /// conversions to preserve the original smart pointer if the cast fails. This
471
- /// is necessary because mutable references cannot be copied, so a failed cast
472
- /// must return ownership of the original reference. For example:
473
- ///
474
- /// ```ignore
475
- /// let mut dev = get_device();
476
- /// // If this fails, we need the original `dev` back to try something else
477
- /// match dev.dynamic_cast_mut::<FooDevice>() {
478
- /// Ok(foodev) => /* use foodev */,
479
- /// Err(dev) => /* still have ownership of dev */
480
- /// }
481
- /// ```
482
- pub trait ObjectCastMut : Sized + ObjectDeref + DerefMut
483
- where
484
- Self :: Target : ObjectType ,
485
- {
486
- /// Safely convert from a derived type to one of its parent types.
487
- ///
488
- /// This is always safe; the [`IsA`] trait provides static verification
489
- /// that `Self` dereferences to `U` or a child of `U`.
490
- fn upcast_mut < ' a , U : ObjectType > ( self ) -> & ' a mut U
491
- where
492
- Self :: Target : IsA < U > ,
493
- Self : ' a ,
494
- {
495
- // SAFETY: soundness is declared via IsA<U>, which is an unsafe trait
496
- unsafe { self . unsafe_cast_mut :: < U > ( ) }
497
- }
498
-
499
- /// Attempt to convert to a derived type.
500
- ///
501
- /// Returns `Ok(..)` if the object is of type `U`, or `Err(self)` if the
502
- /// object if the conversion failed. This is verified at runtime by
503
- /// checking the object's type information.
504
- fn downcast_mut < ' a , U : IsA < Self :: Target > > ( self ) -> Result < & ' a mut U , Self >
505
- where
506
- Self : ' a ,
507
- {
508
- self . dynamic_cast_mut :: < U > ( )
509
- }
510
-
511
- /// Attempt to convert between any two types in the QOM hierarchy.
512
- ///
513
- /// Returns `Ok(..)` if the object is of type `U`, or `Err(self)` if the
514
- /// object if the conversion failed. This is verified at runtime by
515
- /// checking the object's type information.
516
- fn dynamic_cast_mut < ' a , U : ObjectType > ( self ) -> Result < & ' a mut U , Self >
517
- where
518
- Self : ' a ,
519
- {
520
- unsafe {
521
- // SAFETY: upcasting to Object is always valid, and the
522
- // return type is either NULL or the argument itself
523
- let result: * mut U =
524
- object_dynamic_cast ( self . as_object_mut_ptr ( ) , U :: TYPE_NAME . as_ptr ( ) ) . cast ( ) ;
525
-
526
- result. as_mut ( ) . ok_or ( self )
527
- }
528
- }
529
-
530
- /// Convert to any QOM type without verification.
531
- ///
532
- /// # Safety
533
- ///
534
- /// What safety? You need to know yourself that the cast is correct; only
535
- /// use when performance is paramount. It is still better than a raw
536
- /// pointer `cast()`, which does not even check that you remain in the
537
- /// realm of QOM `ObjectType`s.
538
- ///
539
- /// `unsafe_cast::<Object>()` is always safe.
540
- unsafe fn unsafe_cast_mut < ' a , U : ObjectType > ( self ) -> & ' a mut U
541
- where
542
- Self : ' a ,
543
- {
544
- unsafe { & mut * self . as_mut_ptr :: < Self :: Target > ( ) . cast :: < U > ( ) }
545
- }
546
- }
547
-
548
466
impl < T : ObjectType > ObjectDeref for & mut T { }
549
- impl < T : ObjectType > ObjectCastMut for & mut T { }
550
467
551
468
/// Trait a type must implement to be registered with QEMU.
552
469
pub trait ObjectImpl : ObjectType + IsA < Object > {
0 commit comments