Expand description
§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.
Modules§
- facet_
spez - facet-spez
- hacking
- Hacking Guide to Facet
Macros§
- value_
vtable - Creates a
ValueVTablefor a given type.
Structs§
- EnumDef
- Fields for enum types
- Enum
DefBuilder - Builder for EnumDef
- Field
- Describes a field in a struct or tuple
- Field
Builder - Builder for Field
- Field
Flags - Flags that can be applied to fields to modify their behavior
- Hasher
Proxy - Provides an implementation of
core::hash::Hasherfor a given hasher pointer and write function - ListDef
- Fields for list types
- List
DefBuilder - Builder for ListDef
- ListV
Table - Virtual table for a list-like type (like
Vec<T>, but alsoHashSet<T>, etc.) - ListV
Table Builder - Builds a
ListVTable - MapDef
- Fields for map types
- MapDef
Builder - Builder for MapDef
- MapIterV
Table - VTable for an iterator over a map
- MapIterV
Table Builder - Builds a
MapIterVTable - MapV
Table - Virtual table for a Map<K, V>
- MapV
Table Builder - Builds a
MapVTable - Marker
Traits - Bitflags for common marker traits that a type may implement
- Opaque
- A type-erased pointer to an initialized value
- Opaque
Const - A type-erased read-only pointer to an initialized value.
- Opaque
Uninit - A type-erased pointer to an uninitialized value
- Scalar
Def - Definition for scalar types
- Scalar
DefBuilder - Builder for ScalarDef
- Shape
- Schema for reflection of a type
- Shape
Builder - Builder for
Shape - Struct
Def - Common fields for struct-like types
- Struct
DefBuilder - Builder for StructDef
- Type
Name Opts - Options for formatting the name of a type
- ValueV
Table - VTable for common operations that can be performed on any shape
- ValueV
Table Builder - Builds a
ValueVTable - Variant
- Describes a variant of an enum
- Variant
Builder - Builder for Variant
Enums§
- Characteristic
- A characteristic a shape can have
- Def
- The definition of a shape: is it more like a struct, a map, a list?
- Enum
Repr - All possible representations for Rust enums
- Field
Error - Errors encountered when calling
field_by_indexorfield_by_name - Parse
Error - Error returned by
ParseFn - Struct
Kind - Describes the kind of struct (useful for deserializing)
- TryFrom
Error - Error type for TryFrom conversion failures
- Variant
Kind - Represents the different kinds of variants that can exist in a Rust enum
Traits§
- Facet
- Allows querying the
Shapeof a type, which in turn lets us inspect any fields, build a value of this type progressively, etc. - Shape
Ext - Extension trait to provide
is_typeandassert_type
Functions§
- clone_
into_ fn_ for - Generates a [
CloneInPlaceFn] for a concrete type - cmp_
fn_ for - Generates a
CmpFnfor a concrete type - debug_
fn_ for - Generates a
DebugFnfor a concrete type - default_
in_ place_ fn_ for - Generates a
DefaultInPlaceFnfor a concrete type - display_
fn_ for - Generates a
DisplayFnfor a concrete type - drop_
in_ place_ fn_ for - Generates a
DropInPlaceFnfor a concrete type - hash_
fn_ for - Generates a
HashFnfor a concrete type - parse_
fn_ for - Generates a
ParseFnfor a concrete type - partial_
eq_ fn_ for - Generates a
PartialEqFnfor a concrete type - partial_
ord_ fn_ for - Generates a
PartialOrdFnfor a concrete type
Type Aliases§
- Clone
Into Fn - Function to clone a value into another already-allocated value
- CmpFn
- Function to compare two values and return their ordering
- DebugFn
- Function to format a value for debug. If this returns None, the shape did not implement Debug.
- Default
InPlace Fn - Function to set a value to its default in-place
- Display
Fn - Function to format a value for display
- Drop
InPlace Fn - Function to drop a value
- HashFn
- Function to hash a value
- Hasher
Write Fn - Function to write bytes to a hasher
- List
GetItem PtrFn - Get pointer to the item at the given index. Panics if out of bounds.
- List
Init InPlace With Capacity Fn - Initialize a list in place with a given capacity
- List
LenFn - Get the number of items in the list
- List
Push Fn - Push an item to the list
- MapContains
KeyFn - Check if the map contains a key
- MapGet
Value PtrFn - Get pointer to a value for a given key, returns None if not found
- MapInit
InPlace With Capacity Fn - Initialize a map in place with a given capacity
- MapInsert
Fn - Insert a key-value pair into the map
- MapIter
Dealloc Fn - Deallocate the iterator
- MapIter
Fn - Get an iterator over the map
- MapIter
Next Fn - Get the next key-value pair from the iterator
- MapLen
Fn - Get the number of entries in the map
- ParseFn
- Function to parse a value from a string.
- Partial
EqFn - Function to check if two values are partially equal
- Partial
OrdFn - Function to compare two values and return their ordering if comparable
- TryFrom
Fn - Function to try converting from another type
- Type
Name Fn - A function that formats the name of a type.
Derive Macros§
- Facet
- Derive the Facet trait for structs, tuple structs, and enums.