facet_core/
opaque.rs

1use crate::{Def, ScalarAffinity, ScalarDef, ValueVTable, value_vtable};
2use crate::{Facet, Shape, Type, UserType};
3
4/// Helper type for opaque members
5#[repr(transparent)]
6pub struct Opaque<T>(pub T);
7
8unsafe impl<'a, T: 'a> Facet<'a> for Opaque<T> {
9    // Since T is opaque and could be anything, we can't provide much functionality.
10    // Using `()` for the vtable like PhantomData.
11    const VTABLE: &'static ValueVTable =
12        &const { value_vtable!((), |f, _opts| write!(f, "{}", Self::SHAPE.type_identifier)) };
13
14    const SHAPE: &'static Shape<'static> = &const {
15        Shape::builder_for_sized::<Self>()
16            .type_identifier("Opaque")
17            .ty(Type::User(UserType::Opaque))
18            .def(Def::Scalar(
19                ScalarDef::builder()
20                    .affinity(&const { ScalarAffinity::opaque().build() })
21                    .build(),
22            ))
23            .build()
24    };
25}