facet_core/
opaque.rs

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