facet_core/_trait/mod.rs
1#![warn(missing_docs)]
2#![doc = include_str!("../../README.md")]
3
4pub use crate::types::*;
5
6mod impls;
7
8mod macros;
9pub use macros::*;
10
11/// Allows querying the [`Shape`] of a type, which in turn lets us inspect any fields, build a value of
12/// this type progressively, etc.
13///
14/// # Safety
15///
16/// If you implement this wrong, all the safe abstractions in `facet-reflect`,
17/// all the serializers, deserializers, the entire ecosystem is unsafe.
18///
19/// You're responsible for describing the type layout properly, and annotating all the invariants.
20pub unsafe trait Facet: Sized {
21 /// The shape of this type
22 const SHAPE: &'static Shape;
23
24 /// Returns true if the type of `self` is equal to the type of `other`
25 fn type_eq<Other: Facet>() -> bool {
26 Self::SHAPE == Other::SHAPE
27 }
28}