Skip to content

Commit cce819e

Browse files
Introduce core crate
1 parent 23cad83 commit cce819e

File tree

18 files changed

+122
-62
lines changed

18 files changed

+122
-62
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["shapely", "shapely-derive", "shapely-json"]
2+
members = ["shapely", "shapely-core", "shapely-derive", "shapely-json"]
33
resolver = "3"
44

55
[workspace.package]
@@ -11,11 +11,19 @@ license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/bearcove/shapely"
1212
homepage = "https://github.com/bearcove/shapely"
1313
documentation = "https://docs.rs/shapely"
14-
description = "Know the shape of your types"
15-
keywords = ["serialization", "deserialization"]
16-
categories = ["encoding", "parsing"]
14+
description = "One trait for reflection, serialization, deserialization"
15+
keywords = [
16+
"serialization",
17+
"deserialization",
18+
"reflection",
19+
"schema",
20+
"validation",
21+
]
22+
categories = ["encoding", "parsing", "development-tools", "data-structures"]
1723

1824
[workspace.dependencies]
1925
shapely = { version = "1.0.0", path = "shapely" }
26+
shapely-core = { version = "1.0.0", path = "shapely-core" }
2027
shapely-derive = { version = "1.0.0", path = "shapely-derive" }
2128
shapely-json = { version = "1.0.0", path = "shapely-json" }
29+
unsynn = "0.0.25"

shapely-core/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "shapely-core"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
license.workspace = true
8+
repository.workspace = true
9+
homepage.workspace = true
10+
documentation.workspace = true
11+
description = "Core types and traits for the shapely ecosystem, providing fundamental reflection capabilities"
12+
keywords = ["reflection", "introspection", "serialization", "deserialization"]
13+
categories = ["development-tools", "encoding"]
14+
15+
[dependencies]
16+
nonmax = "0.5.5"

shapely-core/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# shapely-core
2+
3+
[![crates.io](https://img.shields.io/crates/v/shapely-core.svg)](https://crates.io/crates/shapely-core)
4+
[![documentation](https://docs.rs/shapely-core/badge.svg)](https://docs.rs/shapely-core)
5+
[![MIT/Apache-2.0 licensed](https://img.shields.io/crates/l/shapely-core.svg)](./LICENSE)
6+
7+
This is the core crate for the shapely ecosystem. It provides the fundamental
8+
types and traits used by other crates in the shapely family.
9+
10+
Note that the main documentation for the shapely project can be found in the
11+
[shapely crate](https://crates.io/crates/shapely). This core crate serves as a
12+
common dependency for:
13+
14+
* The derived proc macro crate [`shapely-derive`] (https://crates.io/crates/shapely-derive)
15+
* Serializers and deserializers (e.g. [`shapely-json`] (https://crates.io/crates/shapely-json))
16+
* Any other crates in the shapely ecosystem
17+
18+
If you're building tools or libraries that interact with shapely's core
19+
functionality, you should depend directly on `shapely-core` rather than the main
20+
`shapely` crate.
21+
22+
For more detailed information and usage examples, please refer to the [shapely crate documentation](https://docs.rs/shapely).
File renamed without changes.
File renamed without changes.

shapely-core/src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::mem::MaybeUninit;
2+
3+
pub use nonmax;
4+
5+
mod hashmap_impl;
6+
mod scalar_impls;
7+
8+
mod shape;
9+
pub use shape::*;
10+
11+
mod slot;
12+
pub use slot::Slot;
13+
14+
mod partial;
15+
pub use partial::*;
16+
17+
mod helpers;
18+
pub use helpers::*;
19+
20+
pub mod mini_typeid;
21+
22+
#[doc(hidden)]
23+
pub mod log;
24+
pub use log::*;
25+
26+
#[cfg(test)]
27+
mod 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.
31+
pub 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+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)