use crate::{Def, value_vtable};
use crate::{Facet, Shape, Type, UserType};

/// Helper type for opaque members
#[repr(transparent)]
pub struct Opaque<T: ?Sized>(pub T);

unsafe impl<'facet, T: 'facet> Facet<'facet> for Opaque<T> {
    const SHAPE: &'static Shape = &const {
        Shape::builder_for_sized::<Self>()
            .type_identifier("Opaque")
            .ty(Type::User(UserType::Opaque))
            .def(Def::Scalar)
            // Since T is opaque and could be anything, we can't provide much functionality.
            // Using `()` for the vtable like PhantomData.
            .vtable(value_vtable!((), |f, _opts| write!(
                f,
                "{}",
                Self::SHAPE.type_identifier
            )))
            .build()
    };
}
