Expand description
§facet
facet provides reflection for Rust: it gives types a SHAPE associated
const with details on the layout, fields, doc comments, attributes, etc.
It can be used for many things, from (de)serialization to pretty-printing, rich debuggers, CLI parsing, reflection in templating engines, code generation, etc.
See https://facet.rs for details.
§Workspace contents
The main facet crate re-exports symbols from:
- facet-core, which defines the main components:
- The
Facettrait and implementations for foreign types (mostlylibstd) - The
Shapestruct along with various vtables and the wholeDeftree - Type-erased pointer helpers like
PtrUninit,PtrConst, andOpaque - Autoderef specialization trick needed for
facet-macros
- The
- facet-macros, which implements the
Facetderive attribute as a fast/light proc macro powered by unsynn
For struct manipulation and reflection, we have:
- facet-reflect, allows building values of arbitrary shapes in safe code, respecting invariants. It also allows peeking at existing values.
Internal crates include:
- facet-testhelpers a simple log logger and color-backtrace configured with the lightweight btparse backend
§Ecosystem
Various crates live under the https://github.com/facet-rs umbrella, and their repositories are kept somewhat-consistent through facet-dev.
Crates are in various states of progress, buyer beware!
In terms of data formats, we have:
- facet-json: JSON format support
- facet-toml: TOML format support
- facet-yaml: YAML format support
- facet-msgpack: MessagePack deserialization
- facet-asn1: ASN.1 format support
- facet-xdr: XDR format support
- facet-kdl: KDL format support (non-functional so far)
Still adjacent to serialization/deserialization, we have:
- facet-urlencoded: URL-encoded form data deserialization
- facet-args: CLI arguments (a-la clap)
As far as utilities go:
- facet-pretty is able to pretty-print Facet types.
- facet-serialize provides generic iterative serialization facilities
- facet-deserialize provides generic iterative deserialization facilities
And the less developed:
- facet-inspect: Provide utilities to inspect the content of a Facet object.
- facet-diff: Provides diffing capabilities for Facet types.
§Extended cinematic universe
Some crates are developed completely independently from the facet org:
- facet-v8 provides an experimental Facet/v8 integration
- facet-openapi (experimental) Generates OpenAPI definitions from types that implement Facet
- facet_generate reflects Facet types into Java, Swift and TypeScript
- multi-array-list provides an experimental
MultiArrayListtype
§Sponsors
Thanks to all individual sponsors:
…along with corporate sponsors:
…without whom this work could not exist.
§Special thanks
The facet logo was drawn by Misiasart.
§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.
Re-exports§
pub use static_assertions;
Modules§
Macros§
- debug
reflect - Forwards to log::debug when the log feature is enabled
- trace
reflect - Forwards to log::trace when the log feature is enabled
- value_
vtable - Creates a
ValueVTablefor a given type. - value_
vtable_ unsized - Similar to
value_vtable!macro but for!Sizedtypes.
Structs§
- Array
Def - Fields for array types
- Array
DefBuilder - Builder for ArrayDef
- Array
Type - Describes a fixed-size array (
[T; N]) - ArrayV
Table - Virtual table for an array
- ArrayV
Table Builder - Builds a
ArrayVTable - Const
Type Id - TypeId equivalent usable in const contexts.
- Enum
DefBuilder - Builder for EnumDef
- Enum
Type - Fields for enum types
- 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
- Field
Iter reflect - An iterator over all the fields of a struct or enum. See
HasFields::fields - FieldV
Table - Vtable for field-specific operations
- FieldV
Table Builder - Builder for FieldVTable
- Fields
ForSerialize Iter reflect - An iterator over the fields of a struct or enum that should be serialized. See
HasFields::fields_for_serialize - Function
Pointer Def - Common fields for function pointer types
- Function
Pointer DefBuilder - Builder for FunctionPointerDef
- Guard
reflect - A guard structure to manage memory allocation and deallocation.
- Hasher
Proxy - Provides an implementation of
core::hash::Hasherfor a given hasher pointer and write function - Heap
Value reflect - A type-erased value stored on the heap
- IterV
Table - VTable for an iterator
- IterV
Table Builder - Builds an
IterVTable - ListDef
- Fields for list types
- List
DefBuilder - Builder for ListDef
- ListV
Table - Virtual table for a list-like type (like
Vec<T>) - ListV
Table Builder - Builds a
ListVTable - Lock
GuardV Table - Functions for manipulating a guard
- Lock
Result - Type-erased result of locking a mutex-like pointer
- MapDef
- Fields for map types
- MapDef
Builder - Builder for MapDef
- 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
- NdArray
Def - Fields for n-dimensional array types
- NdArray
DefBuilder - Builder for NdArrayDef
- NdArrayV
Table - Virtual table for a n-dimensional array type (like
Matrix<T>,Tensor<T>, etc.) - NdArrayV
Table Builder - Builds a
NdArrayVTable - Opaque
- Helper type for opaque members
- Option
Def - Describes an Option — including a vtable to query and alter its state,
and the inner shape (the
TinOption<T>). - Option
DefBuilder - Builder for OptionDef
- OptionV
Table - Virtual table for
Option<T> - OptionV
Table Builder - Builds an
OptionVTable - Partial
reflect - A type-erased, heap-allocated, partially-initialized value.
- Peek
reflect - Lets you read from a value (implements read-only
ValueVTableproxies) - Peek
Enum reflect - Lets you read from an enum (implements read-only enum operations)
- Peek
List reflect - Lets you read from a list (implements read-only
facet_core::ListVTableproxies) - Peek
List Iter reflect - Iterator over a
PeekList - Peek
List Like reflect - Lets you read from a list, array or slice
- Peek
List Like Iter reflect - Iterator over a
PeekListLike - PeekMap
reflect - Lets you read from a map (implements read-only
facet_core::MapVTableproxies) - Peek
MapIter reflect - Iterator over key-value pairs in a
PeekMap - Peek
NdArray reflect - Lets you read from an n-dimensional array (implements read-only
facet_core::NdArrayVTableproxies) - Peek
Option reflect - Lets you read from an option (implements read-only option operations)
- Peek
Pointer reflect - Represents a pointer that can be peeked at during memory inspection.
- PeekSet
reflect - Lets you read from a set
- Peek
SetIter reflect - Iterator over values in a
PeekSet - Peek
Struct reflect - Lets you read from a struct (implements read-only struct operations)
- Peek
Tuple reflect - Lets you read from a tuple
- Pointer
Def - Describes a pointer — including a vtable to query and alter its state, and the inner shape (the pointee type in the pointer).
- Pointer
DefBuilder - Builder for creating a
PointerDef. - Pointer
Flags - Flags to represent various characteristics of pointers
- PointerV
Table - Functions for interacting with a pointer
- PointerV
Table Builder - Builder for creating a
PointerVTable. - PtrConst
- A type-erased read-only pointer to an initialized value.
- PtrConst
Wide - A type-erased, read-only wide pointer to an initialized value.
- PtrMut
- A type-erased pointer to an initialized value
- PtrMut
Wide - A type-erased, mutable wide pointer to an initialized value.
- PtrUninit
- A type-erased pointer to an uninitialized value
- PtrUninit
Wide - A type-erased, wide pointer to an uninitialized value.
- Repr
- Describes base representation of the type
- SetDef
- Fields for set types
- SetDef
Builder - Builder for SetDef
- SetV
Table - Virtual table for a
Set<T> - SetV
Table Builder - Builds a
SetVTable - Shape
- Schema for reflection of a type
- Shape
Builder - Builder for
Shape - Slice
BuilderV Table - Functions for creating and manipulating slice builders.
- Slice
BuilderV Table Builder - Builder for creating a
SliceBuilderVTable. - Slice
Def - Fields for slice types
- Slice
DefBuilder - Builder for SliceDef
- Slice
Type - Describes a slice (
[T]) - SliceV
Table - Virtual table for a slice-like type (like
Vec<T>, but alsoHashSet<T>, etc.) - SliceV
Table Builder - Builds a
SliceVTable - Struct
Builder - Builder for StructType
- Struct
Type - Common fields for struct-like types
- Tuple
Type reflect - Local representation of a tuple type for peek operations
- Type
Name Opts - Options for formatting the name of a type
- Type
Param - Represents a lifetime parameter, e.g.,
'aor'a: 'b + 'c. - Typed
Partial reflect - A typed wrapper around
Partial, for when you want to statically ensure thatbuildgives you the proper type. - Typed
PtrUninit - A pointer to an uninitialized value with a lifetime.
- Union
Type - Common fields for union types
- Unsized
Error - Tried to get the
Layoutof an unsized type - VTable
View - A typed view of a
ValueVTable. - ValueId
reflect - A unique identifier for a peek value
- Value
Pointer Type - Describes the raw/reference pointer
- ValueV
Table Builder - Builds a
ValueVTable - ValueV
Table Builder Unsized - Builds a
ValueVTablefor a!Sizedtype - ValueV
Table Sized - VTable for common operations that can be performed on any
Sizedshape - ValueV
Table Unsized - VTable for common operations that can be performed on any
!Sizedshape - Variant
- Describes a variant of an enum
- Variant
Builder - Builder for Variant
Enums§
- Base
Repr - Underlying byte layout representation
- Characteristic
- A characteristic a shape can have
- Def
- The semantic definition of a shape: is it more like a scalar, a map, a list?
- Enum
Repr - All possible representations for Rust enums — ie. the type/size of the discriminant
- Field
Attribute - An attribute that can be set on a field
- Field
Error - Errors encountered when calling
field_by_indexorfield_by_name - Function
Abi - The calling ABI of a function pointer
- Generic
Ptr - A generic wrapper for either a thin or wide constant pointer. This enables working with both sized and unsized types using a single enum.
- Known
Pointer - Represents common standard library pointer kinds
- List
Like Def reflect - Fields for types which act like lists
- Numeric
Type - Describes numeric types (integer/float)
- Parse
Error - Error returned by
ParseFn - Pointer
Type - Describes all pointer types
- Primitive
Type - Describes built-in primitives (u32, bool, str, etc.)
- Reflect
Error reflect - Errors that can occur when reflecting on types.
- Scalar
Type reflect - All scalar types supported out of the box by peek and poke.
- Sequence
Type - Describes built-in sequence type (array, slice)
- Shape
Attribute - An attribute that can be applied to a shape
- Shape
Layout - Layout of the shape
- Stride
Error reflect - Error that can occur when trying to access an n-dimensional array as strided
- Struct
Kind - Describes the kind of struct (useful for deserializing)
- Textual
Type - Describes textual types (char/string)
- Tracker
Kind reflect - A kind-only version of Tracker
- TryBorrow
Inner Error - Error type returned by
TryBorrowInnerFnwhen attempting to borrow the inner value from a wrapper type. - TryFrom
Error - Error type for TryFrom conversion failures
- TryInto
Inner Error - Error type returned by
TryIntoInnerFnwhen attempting to extract the inner value from a wrapper type. - Type
- The definition of a shape in accordance to rust reference:
- User
Type - User-defined types (structs, enums, unions)
- ValueV
Table - A vtable representing the operations that can be performed on a type, either for sized or unsized types.
- Variant
Attribute - An attribute that can be set on an enum variant
- Variant
Error reflect - Error that can occur when trying to determine variant information
Traits§
- Facet
- Allows querying the
Shapeof a type, which in turn lets us inspect any fields, build a value of this type progressively, etc. - HasFields
reflect - Trait for types that have field methods
- Iter
Item - A kind of item that an
IterVTablereturns
Functions§
- of
- Create a
TypeIdfor a type. - peek_
enum reflect - Returns the enum definition if the shape represents an enum, None otherwise
- peek_
enum_ repr reflect - Returns the enum representation if the shape represents an enum, None otherwise
- peek_
enum_ variants reflect - Returns the enum variants if the shape represents an enum, None otherwise
Type Aliases§
- Array
AsMut PtrFn - Get mutable pointer to the data buffer of the array.
- Array
AsPtr Fn - Get pointer to the data buffer of the array.
- Borrow
Fn - Tries to obtain a reference to the inner value of the pointer.
- Clone
Into Fn - Function to clone a value into another already-allocated value
- Clone
Into FnTyped - Function to clone a value into another already-allocated value
- CmpFn
- Function to compare two values and return their ordering
- CmpFn
Typed - Function to compare two values and return their ordering
- CmpFn
Wide - Function to compare two values and return their ordering (wide pointer version)
- DebugFn
- Function to format a value for debug. If this returns None, the shape did not implement Debug.
- Debug
FnTyped - Function to format a value for debug. If this returns None, the shape did not implement Debug.
- Debug
FnWide - Function to format a value for debug (wide pointer version). If this returns None, the shape did not implement Debug (wide).
- Default
InPlace Fn - Function to set a value to its default in-place
- Default
InPlace FnTyped - Function to set a value to its default in-place
- Display
Fn - Function to format a value for display
- Display
FnTyped - Function to format a value for display
- Display
FnWide - Function to format a value for display (wide pointer version)
- Downgrade
Into Fn - Downgrades a strong pointer to a weak one.
- Drop
InPlace Fn - Function to drop a value
- Drop
InPlace FnWide - Function to drop a value (wide pointer version)
- HashFn
- Function to hash a value
- Hash
FnTyped - Function to hash a value
- Hash
FnWide - Function to hash a value
- Hasher
Write Fn - Function to write bytes to a hasher
- Hasher
Write FnTyped - Function to write bytes to a hasher
- Invariants
Fn - Function to validate the invariants of a value. If it returns false, the value is considered invalid.
- Invariants
FnTyped - Function to validate the invariants of a value. If it returns false, the value is considered invalid.
- Invariants
FnWide - Function to validate the invariants of a value. If it returns false, the value is considered invalid (wide pointer version).
- Iter
Dealloc Fn - Deallocate the iterator
- Iter
Init With Value Fn - Create a new iterator that iterates over the provided value
- Iter
Next Back Fn - Advance the iterator in reverse, returning the next value from the end of the iterator.
- Iter
Next Fn - Advance the iterator, returning the next value from the iterator
- Iter
Size Hint Fn - Return the lower and upper bounds of the iterator, if known.
- List
AsMut PtrFn - Get mutable pointer to the data buffer of the list.
- List
AsPtr Fn - Get pointer to the data buffer of the list.
- List
GetFn - Get pointer to the element at
indexin the list, orNoneif the index is out of bounds. - List
GetMut Fn - Get mutable pointer to the element at
indexin the list, orNoneif the index is 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
- LockFn
- Acquires a lock on a mutex-like pointer
- 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
- MapLen
Fn - Get the number of entries in the map
- NdArray
AsMut PtrFn - Get mutable pointer to the data buffer of the array.
- NdArray
AsPtr Fn - Get pointer to the data buffer of the array.
- NdArray
Byte Stride Fn - Get the i-th stride in the array in bytes, or
Noneif the dimension index is out of bounds. - NdArray
Count Fn - Get the total count of elements in the array.
- NdArray
DimFn - Get the i-th dimension in the array, or
Noneif the dimension index is out of bounds. - NdArray
GetFn - Get pointer to the element at
indexin the array, orNoneif the index is out of bounds. - NdArray
GetMut Fn - Get mutable pointer to the element at
indexin the array, orNoneif the index is out of bounds. - NdArrayN
DimFn - Get the number of dimensions in the array.
- NewInto
Fn - Creates a new pointer wrapping the given value.
- Option
GetValue Fn - Get the value contained in an option, if present
- Option
Init None Fn - Initialize an option with None
- Option
Init Some Fn - Initialize an option with Some(value)
- Option
IsSome Fn - Check if an option contains a value
- Option
Replace With Fn - Replace an existing option with a new value
- ParseFn
- Function to parse a value from a string.
- Parse
FnTyped - Function to parse a value from a string.
- Partial
EqFn - Function to check if two values are partially equal
- Partial
EqFn Typed - Function to check if two values are partially equal
- Partial
EqFn Wide - Function to check if two values are partially equal (wide pointer version)
- Partial
OrdFn - Function to compare two values and return their ordering if comparable
- Partial
OrdFn Typed - Function to compare two values and return their ordering if comparable
- Partial
OrdFn Wide - Function to compare two values and return their ordering if comparable (wide pointer version)
- ReadFn
- Acquires a read lock on a reader-writer lock-like pointer
- SetContains
Fn - Check if the set contains a value
- SetInit
InPlace With Capacity Fn - Initialize a set in place with a given capacity
- SetInsert
Fn - Insert a value in the set if not already contained, returning true if the value wasn’t present before
- SetLen
Fn - Get the number of values in the set
- Skip
Serializing IfFn - A function that, if present, determines whether field should be included in the serialization step.
- Slice
AsMut PtrFn - Get mutable pointer to the data buffer of the slice
- Slice
AsPtr Fn - Get pointer to the data buffer of the slice
- Slice
Builder Convert Fn - Converts a slice builder into a pointer. This takes ownership of the builder and frees the backing storage.
- Slice
Builder Free Fn - Frees a slice builder without converting it into a pointer
- Slice
Builder NewFn - Creates a new slice builder for a pointer: ie. for
Arc<[u8]>, it builds aVec<u8>internally, to which you can push, and then turn into anArc<[u8]>at the last stage. - Slice
Builder Push Fn - Pushes a value into a slice builder.
- Slice
LenFn - Get the number of items in the slice
- TryBorrow
Inner Fn - Function to borrow the inner value from a transparent/newtype wrapper without copying.
- TryBorrow
Inner FnTyped - Function to borrow the inner value from a transparent/newtype wrapper without copying.
- TryBorrow
Inner FnWide - Function to borrow the inner value from a transparent/newtype wrapper without copying (wide pointer version).
- TryFrom
Fn - Function to try converting from another type
- TryFrom
FnTyped - Function to try converting from another type
- TryInto
Inner Fn - Function to convert a transparent/newtype wrapper into its inner type.
- TryInto
Inner FnTyped - Function to convert a transparent/newtype wrapper into its inner type.
- Tuple
Field reflect - Field index and associated peek value
- Type
Name Fn - A function that formats the name of a type.
- Upgrade
Into Fn - Tries to upgrade the weak pointer to a strong one.
- WriteFn
- Acquires a write lock on a reader-writer lock-like pointer