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 = "bytes")]
36mod impls_bytes;
37
38#[cfg(feature = "camino")]
39mod impls_camino;
40
41#[cfg(feature = "ordered-float")]
42mod impls_ordered_float;
43
44#[cfg(feature = "uuid")]
45mod impls_uuid;
46
47#[cfg(feature = "ulid")]
48mod impls_ulid;
49
50#[cfg(feature = "time")]
51mod impls_time;
52
53#[cfg(feature = "chrono")]
54mod impls_chrono;
55
56#[cfg(feature = "url")]
57mod impls_url;
58
59#[cfg(feature = "jiff02")]
60mod impls_jiff;
61
62// Const type Id
63mod typeid;
64pub use typeid::*;
65
66// Type definitions
67mod types;
68#[allow(unused_imports)] // wtf clippy? we're re-exporting?
69pub use types::*;
70
71/// Allows querying the [`Shape`] of a type, which in turn lets us inspect any fields, build a value of
72/// this type progressively, etc.
73///
74/// The `'facet` lifetime allows `Facet` to be derived for types that borrow from something else.
75///
76/// # Safety
77///
78/// If you implement this wrong, all the safe abstractions in `facet-reflect`,
79/// all the serializers, deserializers, the entire ecosystem is unsafe.
80///
81/// You're responsible for describing the type layout properly, and annotating all the invariants.
82pub unsafe trait Facet<'facet>: 'facet {
83 /// The shape of this type
84 ///
85 /// Shape embeds all other constants of this trait.
86 const SHAPE: &'static Shape;
87
88 /// Function pointers to perform various operations: print the full type
89 /// name (with generic type parameters), use the Display implementation,
90 /// the Debug implementation, build a default value, clone, etc.
91 ///
92 /// If [`Self::SHAPE`] has `ShapeLayout::Unsized`, then the parent pointer needs to be passed.
93 ///
94 /// There are more specific vtables in variants of [`Def`]
95 const VTABLE: &'static ValueVTable;
96}