facet_core/impls/builtin.rs
1use crate::{Facet, Opaque, OpaqueBorrow, Shape, VarianceDesc};
2
3// Opaque<T> is a lifetime boundary; require 'static to prevent lifetime laundering
4// through reflection. See issue #1563 for details.
5unsafe impl<'facet, T: 'static> Facet<'facet> for Opaque<T> {
6 const SHAPE: &'static Shape = &const {
7 Shape::builder_for_sized::<Opaque<T>>("Opaque")
8 .variance(VarianceDesc::INVARIANT)
9 .build()
10 };
11}
12
13// OpaqueBorrow<'facet, T> is used by derive-generated field-level `#[facet(opaque)]`
14// wrappers so borrowed fields can stay tied to the active Facet lifetime.
15unsafe impl<'facet, T: 'facet> Facet<'facet> for OpaqueBorrow<'facet, T> {
16 const SHAPE: &'static Shape = &const {
17 // Reuse Opaque<T>'s shape identity for compatibility with APIs/tests that
18 // set field-level opaque values via Opaque<T>.
19 Shape::builder_for_sized::<Opaque<T>>("Opaque")
20 .variance(VarianceDesc::INVARIANT)
21 .build()
22 };
23}