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#[cfg(feature = "camino")]
32mod impls_camino;
33
34// Const type Id
35mod typeid;
36pub use typeid::*;
37
38// Type definitions
39mod types;
40#[allow(unused_imports)] // wtf clippy? we're re-exporting?
41pub use types::*;
42
43/// Allows querying the [`Shape`] of a type, which in turn lets us inspect any fields, build a value of
44/// this type progressively, etc.
45///
46/// # Safety
47///
48/// If you implement this wrong, all the safe abstractions in `facet-reflect`,
49/// all the serializers, deserializers, the entire ecosystem is unsafe.
50///
51/// You're responsible for describing the type layout properly, and annotating all the invariants.
52pub unsafe trait Facet<'a>: Sized + 'a {
53    /// The shape of this type
54    const SHAPE: &'static Shape;
55
56    /// Returns true if the type of `self` is equal to the type of `other`
57    fn type_eq<Other: Facet<'a>>() -> bool {
58        Self::SHAPE == Other::SHAPE
59    }
60}