Skip to main content

ObjectRefCast

Trait ObjectRefCast 

Source
pub trait ObjectRefCast: ObjectRefCore + AnyCompatible {
    // Provided method
    fn try_cast<B>(self) -> Result<B>
       where B: ObjectRefCore + AnyCompatible { ... }
}
Expand description

Runtime-checked casting between arbitrary ObjectRef types.

The cast uses the target’s AnyCompatible::check_any_strict implementation, mirroring the semantics of ObjectRef::as<T> in C++. This supports both object hierarchies and parameterized object containers.

This trait is blanket-implemented for every ObjectRefCore type that is also AnyCompatible.

Provided Methods§

Source

fn try_cast<B>(self) -> Result<B>

Consume self and rewrap the underlying object as B without copying.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§