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, "Opaque")) };
13
14    const SHAPE: &'static Shape<'static> = &const {
15        Shape::builder_for_sized::<Self>()
16            .ty(Type::User(UserType::Opaque))
17            .def(Def::Scalar(
18                ScalarDef::builder()
19                    .affinity(&const { ScalarAffinity::opaque().build() })
20                    .build(),
21            ))
22            .build()
23    };
24}