shapely_core/lib.rs
1use std::mem::MaybeUninit;
2
3pub use nonmax;
4
5mod hashmap_impl;
6mod scalar_impls;
7
8mod shape;
9pub use shape::*;
10
11mod slot;
12pub use slot::Slot;
13
14mod partial;
15pub use partial::*;
16
17mod helpers;
18pub use helpers::*;
19
20pub mod mini_typeid;
21
22#[doc(hidden)]
23pub mod log;
24pub use log::*;
25
26#[cfg(test)]
27mod tests;
28
29/// Allows querying the [Shape] of a type, which in turn lets us inspect any fields, build a value of
30/// this type progressively, etc.
31pub trait Shapely: Sized {
32 /// Returns the shape of this type
33 fn shape() -> Shape;
34
35 /// Returns a shape def (a function that can describe this shape)
36 fn shape_desc() -> ShapeDesc {
37 ShapeDesc(Self::shape)
38 }
39
40 /// Allocates this shape on the heap and return a partial that allows gradually initializing its fields.
41 fn partial() -> Partial<'static> {
42 Partial::alloc(Self::shape_desc())
43 }
44
45 /// Initializes a `Partial` from a borrowed `MaybeUninit<Self>`.
46 ///
47 /// Before calling assume_init, make sure to call Partial.build_in_place().
48 fn partial_from_uninit(dest: &mut MaybeUninit<Self>) -> Partial<'_> {
49 Partial::borrow(dest)
50 }
51
52 // TODO: partial_from_mut? where all the fields are already initialized?
53}