Crate facet_core

Source
Expand description

Facet logo - a reflection library for Rust

Coverage Status free of syn crates.io documentation MIT/Apache-2.0 licensed Discord

Logo by Misiasart

Thanks to all individual and corporate sponsors, without whom this work could not exist:

Ko-fi GitHub Sponsors Patreon Zed Depot

Defines the core types and traits used throughout the facet ecosystem for runtime reflection:

  • Facet: exposes a SHAPE associated const
  • Shape: The central type that describes the memory layout and capabilities of a type
  • Various vtables that define how to manipulate types at runtime
  • The Def tree, which describes type definitions (structs, enums, etc.)

This crate is foundational to facet’s reflection capabilities, providing the type system that enables runtime type manipulation.

§License

Licensed under either of:

at your option.

Modules§

spez
Auto-deref specialization helpers for the Facet reflection system

Macros§

value_vtable
Creates a ValueVTable for a given type.
value_vtable_unsized
Similar to value_vtable! macro but for !Sized types.

Structs§

ArrayDef
Fields for array types
ArrayDefBuilder
Builder for ArrayDef
ArrayType
Describes a fixed-size array ([T; N])
ArrayVTable
Virtual table for an array
ArrayVTableBuilder
Builds a ArrayVTable
ConstTypeId
TypeId equivalent usable in const contexts.
EnumDefBuilder
Builder for EnumDef
EnumType
Fields for enum types
Field
Describes a field in a struct or tuple
FieldBuilder
Builder for Field
FieldFlags
Flags that can be applied to fields to modify their behavior
FieldVTable
Vtable for field-specific operations
FieldVTableBuilder
Builder for FieldVTable
FunctionPointerDef
Common fields for function pointer types
FunctionPointerDefBuilder
Builder for FunctionPointerDef
HasherProxy
Provides an implementation of core::hash::Hasher for a given hasher pointer and write function
IterVTable
VTable for an iterator
IterVTableBuilder
Builds an IterVTable
ListDef
Fields for list types
ListDefBuilder
Builder for ListDef
ListVTable
Virtual table for a list-like type (like Vec<T>)
ListVTableBuilder
Builds a ListVTable
LockGuardVTable
Functions for manipulating a guard
LockResult
Type-erased result of locking a mutex-like smart pointer
MapDef
Fields for map types
MapDefBuilder
Builder for MapDef
MapVTable
Virtual table for a Map<K, V>
MapVTableBuilder
Builds a MapVTable
MarkerTraits
Bitflags for common marker traits that a type may implement
Opaque
Helper type for opaque members
OptionDef
Describes an Option — including a vtable to query and alter its state, and the inner shape (the T in Option<T>).
OptionDefBuilder
Builder for OptionDef
OptionVTable
Virtual table for Option<T>
OptionVTableBuilder
Builds an OptionVTable
PtrConst
A type-erased read-only pointer to an initialized value.
PtrConstWide
A type-erased, read-only wide pointer to an initialized value.
PtrMut
A type-erased pointer to an initialized value
PtrMutWide
A type-erased, mutable wide pointer to an initialized value.
PtrUninit
A type-erased pointer to an uninitialized value
PtrUninitWide
A type-erased, wide pointer to an uninitialized value.
Repr
Describes base representation of the type
SetDef
Fields for set types
SetDefBuilder
Builder for SetDef
SetVTable
Virtual table for a Set<T>
SetVTableBuilder
Builds a SetVTable
Shape
Schema for reflection of a type
ShapeBuilder
Builder for Shape
SliceBuilderVTable
Functions for creating and manipulating slice builders.
SliceBuilderVTableBuilder
Builder for creating a SliceBuilderVTable.
SliceDef
Fields for slice types
SliceDefBuilder
Builder for SliceDef
SliceType
Describes a slice ([T])
SliceVTable
Virtual table for a slice-like type (like Vec<T>, but also HashSet<T>, etc.)
SliceVTableBuilder
Builds a SliceVTable
SmartPointerDef
Describes a smart pointer — including a vtable to query and alter its state, and the inner shape (the pointee type in the smart pointer).
SmartPointerDefBuilder
Builder for creating a SmartPointerDef.
SmartPointerFlags
Flags to represent various characteristics of smart pointers
SmartPointerVTable
Functions for interacting with a smart pointer
SmartPointerVTableBuilder
Builder for creating a SmartPointerVTable.
StructBuilder
Builder for StructType
StructType
Common fields for struct-like types
TypeNameOpts
Options for formatting the name of a type
TypeParam
Represents a lifetime parameter, e.g., 'a or 'a: 'b + 'c.
TypedPtrUninit
A pointer to an uninitialized value with a lifetime.
UnionType
Common fields for union types
UnsizedError
Tried to get the Layout of an unsized type
VTableView
A typed view of a ValueVTable.
ValuePointerType
Describes the raw/reference pointer
ValueVTableBuilder
Builds a ValueVTable
ValueVTableBuilderUnsized
Builds a ValueVTable for a !Sized type
ValueVTableSized
VTable for common operations that can be performed on any Sized shape
ValueVTableUnsized
VTable for common operations that can be performed on any !Sized shape
Variant
Describes a variant of an enum
VariantBuilder
Builder for Variant

Enums§

BaseRepr
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?
EnumRepr
All possible representations for Rust enums — ie. the type/size of the discriminant
FieldAttribute
An attribute that can be set on a field
FieldError
Errors encountered when calling field_by_index or field_by_name
FunctionAbi
The calling ABI of a function pointer
GenericPtr
A generic wrapper for either a thin or wide constant pointer. This enables working with both sized and unsized types using a single enum.
KnownSmartPointer
Represents common standard library smart pointer kinds
NumericType
Describes numeric types (integer/float)
ParseError
Error returned by ParseFn
PointerType
Describes all pointer types
PrimitiveType
Describes built-in primitives (u32, bool, str, etc.)
SequenceType
Describes built-in sequence type (array, slice)
ShapeAttribute
An attribute that can be applied to a shape
ShapeLayout
Layout of the shape
StructKind
Describes the kind of struct (useful for deserializing)
TextualType
Describes textual types (char/string)
TryBorrowInnerError
Error type returned by TryBorrowInnerFn when attempting to borrow the inner value from a wrapper type.
TryFromError
Error type for TryFrom conversion failures
TryIntoInnerError
Error type returned by TryIntoInnerFn when attempting to extract the inner value from a wrapper type.
Type
The definition of a shape in accordance to rust reference:
UserType
User-defined types (structs, enums, unions)
ValueVTable
A vtable representing the operations that can be performed on a type, either for sized or unsized types.
VariantAttribute
An attribute that can be set on an enum variant

Traits§

Facet
Allows querying the Shape of a type, which in turn lets us inspect any fields, build a value of this type progressively, etc.
IterItem
A kind of item that an IterVTable returns

Functions§

of
Create a TypeId for a type.

Type Aliases§

ArrayAsMutPtrFn
Get mutable pointer to the data buffer of the array.
ArrayAsPtrFn
Get pointer to the data buffer of the array.
BorrowFn
Tries to obtain a reference to the inner value of the smart pointer.
CloneIntoFn
Function to clone a value into another already-allocated value
CloneIntoFnTyped
Function to clone a value into another already-allocated value
CmpFn
Function to compare two values and return their ordering
CmpFnTyped
Function to compare two values and return their ordering
CmpFnWide
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.
DebugFnTyped
Function to format a value for debug. If this returns None, the shape did not implement Debug.
DebugFnWide
Function to format a value for debug (wide pointer version). If this returns None, the shape did not implement Debug (wide).
DefaultInPlaceFn
Function to set a value to its default in-place
DefaultInPlaceFnTyped
Function to set a value to its default in-place
DisplayFn
Function to format a value for display
DisplayFnTyped
Function to format a value for display
DisplayFnWide
Function to format a value for display (wide pointer version)
DowngradeIntoFn
Downgrades a strong pointer to a weak one.
DropInPlaceFn
Function to drop a value
DropInPlaceFnWide
Function to drop a value (wide pointer version)
HashFn
Function to hash a value
HashFnTyped
Function to hash a value
HashFnWide
Function to hash a value
HasherWriteFn
Function to write bytes to a hasher
HasherWriteFnTyped
Function to write bytes to a hasher
InvariantsFn
Function to validate the invariants of a value. If it returns false, the value is considered invalid.
InvariantsFnTyped
Function to validate the invariants of a value. If it returns false, the value is considered invalid.
InvariantsFnWide
Function to validate the invariants of a value. If it returns false, the value is considered invalid (wide pointer version).
IterDeallocFn
Deallocate the iterator
IterInitWithValueFn
Create a new iterator that iterates over the provided value
IterNextBackFn
Advance the iterator in reverse, returning the next value from the end of the iterator.
IterNextFn
Advance the iterator, returning the next value from the iterator
IterSizeHintFn
Return the lower and upper bounds of the iterator, if known.
ListAsMutPtrFn
Get mutable pointer to the data buffer of the list.
ListAsPtrFn
Get pointer to the data buffer of the list.
ListGetFn
Get pointer to the element at index in the list, or None if the index is out of bounds.
ListGetMutFn
Get mutable pointer to the element at index in the list, or None if the index is out of bounds.
ListInitInPlaceWithCapacityFn
Initialize a list in place with a given capacity
ListLenFn
Get the number of items in the list
ListPushFn
Push an item to the list
LockFn
Acquires a lock on a mutex-like smart pointer
MapContainsKeyFn
Check if the map contains a key
MapGetValuePtrFn
Get pointer to a value for a given key, returns None if not found
MapInitInPlaceWithCapacityFn
Initialize a map in place with a given capacity
MapInsertFn
Insert a key-value pair into the map
MapLenFn
Get the number of entries in the map
NewIntoFn
Creates a new smart pointer wrapping the given value.
OptionGetValueFn
Get the value contained in an option, if present
OptionInitNoneFn
Initialize an option with None
OptionInitSomeFn
Initialize an option with Some(value)
OptionIsSomeFn
Check if an option contains a value
OptionReplaceWithFn
Replace an existing option with a new value
ParseFn
Function to parse a value from a string.
ParseFnTyped
Function to parse a value from a string.
PartialEqFn
Function to check if two values are partially equal
PartialEqFnTyped
Function to check if two values are partially equal
PartialEqFnWide
Function to check if two values are partially equal (wide pointer version)
PartialOrdFn
Function to compare two values and return their ordering if comparable
PartialOrdFnTyped
Function to compare two values and return their ordering if comparable
PartialOrdFnWide
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 smart pointer
SetContainsFn
Check if the set contains a value
SetInitInPlaceWithCapacityFn
Initialize a set in place with a given capacity
SetInsertFn
Insert a value in the set if not already contained, returning true if the value wasn’t present before
SetLenFn
Get the number of values in the set
SkipSerializingIfFn
A function that, if present, determines whether field should be included in the serialization step.
SliceAsMutPtrFn
Get mutable pointer to the data buffer of the slice
SliceAsPtrFn
Get pointer to the data buffer of the slice
SliceBuilderConvertFn
Converts a slice builder into a smart pointer. This takes ownership of the builder and frees the backing storage.
SliceBuilderFreeFn
Frees a slice builder without converting it into a smart pointer
SliceBuilderNewFn
Creates a new slice builder for a smart pointer: ie. for Arc<[u8]>, it builds a Vec<u8> internally, to which you can push, and then turn into an Arc<[u8]> at the last stage.
SliceBuilderPushFn
Pushes a value into a slice builder.
SliceLenFn
Get the number of items in the slice
TryBorrowInnerFn
Function to borrow the inner value from a transparent/newtype wrapper without copying.
TryBorrowInnerFnTyped
Function to borrow the inner value from a transparent/newtype wrapper without copying.
TryBorrowInnerFnWide
Function to borrow the inner value from a transparent/newtype wrapper without copying (wide pointer version).
TryFromFn
Function to try converting from another type
TryFromFnTyped
Function to try converting from another type
TryIntoInnerFn
Function to convert a transparent/newtype wrapper into its inner type.
TryIntoInnerFnTyped
Function to convert a transparent/newtype wrapper into its inner type.
TypeNameFn
A function that formats the name of a type.
UpgradeIntoFn
Tries to upgrade the weak pointer to a strong one.
WriteFn
Acquires a write lock on a reader-writer lock-like smart pointer