1#![warn(missing_docs)]
2#![doc = include_str!("../README.md")]
3
4use std::mem::MaybeUninit;
5
6mod impls;
7
8mod scalar_contents;
9pub use scalar_contents::ScalarContents;
10
11mod shape;
12pub use shape::*;
13
14mod slot;
15pub use slot::Slot;
16
17mod partial;
18pub use partial::*;
19
20mod helpers;
21pub use helpers::*;
22
23pub mod mini_typeid;
24
25#[doc(hidden)]
26pub mod log;
27pub use log::*;
28
29#[cfg(test)]
30mod tests;
31
32#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct Bytes(pub Vec<u8>);
35
36impl Shapely for Bytes {
37 fn shape() -> Shape {
38 Shape {
39 name: |f, _opts| write!(f, "Bytes"),
40 typeid: mini_typeid::of::<Self>(),
41 layout: std::alloc::Layout::new::<Self>(),
42 innards: Innards::Scalar(Scalar::Bytes),
43 set_to_default: Some(|addr: *mut u8| unsafe {
44 *(addr as *mut Bytes) = Bytes(Vec::new());
45 }),
46 drop_in_place: Some(|addr: *mut u8| unsafe {
47 std::ptr::drop_in_place(addr as *mut Bytes);
48 }),
49 }
50 }
51}
52
53pub trait Shapely: Sized {
56 fn shape() -> Shape;
58
59 fn shape_desc() -> ShapeDesc {
61 ShapeDesc(Self::shape)
62 }
63
64 fn partial() -> Partial<'static> {
66 Partial::alloc(Self::shape_desc())
67 }
68
69 fn partial_from_uninit(dest: &mut MaybeUninit<Self>) -> Partial<'_> {
73 Partial::borrow(dest)
74 }
75
76 }