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// Opaque wrapper utility
18mod opaque;
19pub use opaque::*;
20
21// Specialization utilities
22pub mod spez;
23
24// Definition for `core::` types
25mod impls_core;
26
27// Definition for `alloc::` types
28#[cfg(feature = "alloc")]
29mod impls_alloc;
30
31// Definition for `std::` types (that aren't in `alloc` or `core)
32#[cfg(feature = "std")]
33mod impls_std;
34
35#[cfg(feature = "camino")]
36mod impls_camino;
37
38#[cfg(feature = "ordered-float")]
39mod impls_ordered_float;
40
41#[cfg(feature = "uuid")]
42mod impls_uuid;
43
44#[cfg(feature = "ulid")]
45mod impls_ulid;
46
47#[cfg(feature = "time")]
48mod impls_time;
49
50#[cfg(feature = "url")]
51mod impls_url;
52
53#[cfg(feature = "jiff02")]
54mod impls_jiff;
55
56// Const type Id
57mod typeid;
58pub use typeid::*;
59
60// Type definitions
61mod types;
62#[allow(unused_imports)] // wtf clippy? we're re-exporting?
63pub use types::*;
64
65/// Allows querying the [`Shape`] of a type, which in turn lets us inspect any fields, build a value of
66/// this type progressively, etc.
67///
68/// # Safety
69///
70/// If you implement this wrong, all the safe abstractions in `facet-reflect`,
71/// all the serializers, deserializers, the entire ecosystem is unsafe.
72///
73/// You're responsible for describing the type layout properly, and annotating all the invariants.
74pub unsafe trait Facet<'a>: 'a {
75 /// The shape of this type
76 ///
77 /// Shape embeds all other constants of this trait.
78 const SHAPE: &'static Shape<'static>;
79
80 /// Function pointers to perform various operations: print the full type
81 /// name (with generic type parameters), use the Display implementation,
82 /// the Debug implementation, build a default value, clone, etc.
83 ///
84 /// If [`Self::SHAPE`] has `ShapeLayout::Unsized`, then the parent pointer needs to be passed.
85 ///
86 /// There are more specific vtables in variants of [`Def`]
87 const VTABLE: &'static ValueVTable;
88}