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