facet
Thanks to all individual and corporate sponsors, without whom this work could not exist:
facet provides runtime reflection for Rust.
Any type that implements Facet trait returns a Shape, which describes:
- The memory layout of the type
- Its definition: struct fields, underlying type for newtypes, etc.
- How to drop it in place
The Poke type is able to allocate (or work from a &mut MaybeUninit<T>)
any Facet type, and gradually initialize its fields — until the fully-built
value is moved out of the partial.
The Peek type helps perform read operations on any Facet type.
It comes with a derive macro that uses unsynn for speed of compilation.
The core crates, facet-trait, facet-types etc. are nostd-friendly.
Ecosystem
The main facet crate re-exports symbols from:
- facet-trait, which defines the main
Facettrait and implements it for foreign types (mostlylibstd) - facet-types, which defines the
Shapestruct, along with various vtables and the wholeDeftree - facet-opaque, which provides helpers around type-erased pointers like
OpaqueUninit,OpaqueConst,Opaque - facet-derive, which implements the
Facetderive attribute as a fast/light proc macro powered by unsynn - facet-spez, which implements an autoderef specialization trick needed for
facet-derive - facet-peek, which allows reading arbitrary
Facettypes - facet-poke, which allows building/altering arbitrary
Facettypes
facet supports deserialization from multiple data formats through dedicated crates:
- facet-json: JSON deserialization
- facet-yaml: YAML deserialization
- facet-msgpack: MessagePack deserialization
- facet-urlencoded: URL-encoded form data deserialization
Additionally:
- facet-pretty is able to pretty-print Facet types.
- facet-codegen is internal and generates some of the code of
facet-core
Example usage
facet-json is the one that gets updated first — look at it.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.