pub unsafe trait Opaquable: Sized {
    type OpaqueTarget;

    // Provided method
    fn into_opaque(self) -> Self::OpaqueTarget { ... }
}
Expand description

Describes an opaquable object.

This trait provides a safe many-traits-to-one conversion. For instance, concrete vtable types get converted to c_void types, and so on.

Safety

Implementor of this trait must ensure the same layout of regular and opaque data. Generally, this means using the same structure, but taking type T and converting it to c_void, but it is not limited to that.

In addition, it is key to know that any functions on the type that expect a concrete type parameter become undefined behaviour. For instance, moving out of a opaque Box is undefined behaviour.

Required Associated Types§

Provided Methods§

source

fn into_opaque(self) -> Self::OpaqueTarget

Transform self into an opaque version of the trait object.

The opaque version safely destroys type information, and after this point there is no way back.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Opaquable for ()

source§

impl<'a, T> Opaquable for &'a T

source§

impl<'a, T> Opaquable for &'a mut T

§

type OpaqueTarget = &'a mut c_void

source§

impl<T: Opaquable> Opaquable for PhantomData<T>

Implementors§