facet_core/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![warn(clippy::std_instead_of_core)]
4#![warn(clippy::std_instead_of_alloc)]
5#![doc = include_str!("../README.md")]
6
7#[cfg(feature = "alloc")]
8extern crate alloc;
9
10mod macros;
11pub use macros::*;
12
13// Opaque pointer utilities
14mod ptr;
15pub use ptr::*;
16
17// Specialization utilities
18pub mod spez;
19
20// Definition for `core::` types
21mod impls_core;
22
23// Definition for `alloc::` types
24#[cfg(feature = "alloc")]
25mod impls_alloc;
26
27// Definition for `std::` types (that aren't in `alloc` or `core)
28#[cfg(feature = "std")]
29mod impls_std;
30
31// Const type Id
32mod typeid;
33pub use typeid::*;
34
35// Type definitions
36mod types;
37#[allow(unused_imports)] // wtf clippy? we're re-exporting?
38pub use types::*;
39
40/// Allows querying the [`Shape`] of a type, which in turn lets us inspect any fields, build a value of
41/// this type progressively, etc.
42///
43/// # Safety
44///
45/// If you implement this wrong, all the safe abstractions in `facet-reflect`,
46/// all the serializers, deserializers, the entire ecosystem is unsafe.
47///
48/// You're responsible for describing the type layout properly, and annotating all the invariants.
49pub unsafe trait Facet: Sized {
50    /// The shape of this type
51    const SHAPE: &'static Shape;
52
53    /// Returns true if the type of `self` is equal to the type of `other`
54    fn type_eq<Other: Facet>() -> bool {
55        Self::SHAPE == Other::SHAPE
56    }
57}