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