General purpose reflection library for Rust.
🚨 Warning 🚨
This library is still experimental and should not be used for anything serious, yet. Many things are still undocumented and breaking changes are to be expected, though we do adhere to semver.
Examples
Access a field by its string name and mutate it
use ;
let mut foo = Foo ;
# .unwrap;
Iterate over all fields
use ;
// A function that iterates over the fields in an enum and mutates them.
# .unwrap;
Query value and type information using key paths
use ;
// Some complex nested data type.
let user = User ;
// Build a key path that represents accessing `.employer::Some.0.countries[0].name`.
//
// `::Some` means to access the `Some` variant of `Option<Company>`.
let path = field.variant.field.field.get.field;
// Get the value at the key path.
assert_eq!;
// Key paths can also be constructed using the `key_path!` macro.
// This invocation expands the same code we have above.
let path = key_path!;
// Use the same key path to query type information. You don't need a value
// of the type to access its type information.
let user_type = type_descriptor;
assert!;
Using opaque Value types
use ;
;
# .unwrap;
Inspiration
The design of this library is heavily inspired by bevy_reflect but with a few key
differences:
speedyintegration which is useful for marshalling data perhaps to send it across FFI.- A [
Value] type that can be serialized and deserialized without using trait objects. - More [type information][type_info] captured.
- Add meta data to types which becomes part of the type information.
- [Key paths][mod@key_path] for querying value and type information.
- No dependencies on
bevyspecific crates. #![no_std]support.
Feature flags
mirror-mirror uses a set of [feature flags] to optionally reduce the number of dependencies.
The following optional features are available:
| Name | Description | Default? |
|---|---|---|
std |
Enables using the standard library (core and alloc are always required) |
Yes |
speedy |
Enables speedy support for most types |
Yes |
serde |
Enables serde support for most types |
Yes |