Function try_as_dyn
const fn try_as_dyn<T: Any + 'static, U: ptr::Pointee<Metadata = ptr::DynMetadata<U>> + ?Sized + 'static>(t: &T) -> Option<&U>
Returns Some(&U) if T can be coerced to the trait object type U. Otherwise, it returns None.
Compile-time failures
Determining whether T can be coerced to the trait object type U requires compiler trait resolution.
In some cases, that resolution can exceed the recursion limit,
and compilation will fail instead of this function returning None.
Examples
use try_as_dyn;
;
; // does not implement Animal
let dog = Dog;
let rock = Rock;
let as_animal: = ;
assert_eq!;
let not_an_animal: = ;
assert!;