1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! `typex` is a lightweight Rust library for inspecting, traversing, comparing
//! and mutating values at runtime without knowing their concrete types. It
//! supports `no_std` environments with `alloc`.
//!
//! ## Available types
//!
//! - Reflection traits: [`Meta`] and [`MetaMut`]
//! - Owned objects: [`Object`], [`ObjectMut`] and [`SendObject`]
//! - Object trait: [`ObjectOps`]
//! - Borrowed views: [`ObjectRef`] and [`ObjectRefMut`]
//! - Typed map access: [`TypedMapAccess`] and [`TypedMapAccessMut`]
//! - Paths: [`PathSegment`], [`OwnedPath`] and [`TypedPath`]
//! - Mutations: [`PatchOperation`], [`MutationBatch`] and [`MutationRollback`]
//! - Type metadata: [`TypeInfo`], [`ValueKind`] and [`AccessKind`]
//! - Structural shapes: [`Reflect`] and [`ReflectMut`]
//! - Shape access: [`StructAccess`], [`TupleAccess`], [`EnumAccess`],
//! [`SequenceAccess`], [`KeyedSequenceAccess`] and [`MapAccess`], with
//! [`VariantFields`] for the fields of an enum variant
//! - Mutable shape access: [`StructAccessMut`], [`TupleAccessMut`],
//! [`EnumAccessMut`], [`SequenceAccessMut`], [`KeyedSequenceAccessMut`],
//! [`MapAccessMut`] and [`OptionAccessMut`], with [`VariantFieldsMut`]
//! - Type-keyed maps: [`TypeMap`]
//!
//! ## Derive macros
//!
//! The [`Meta`] and [`MetaMut`] derive macros are provided by
//! [`typex_derive`](https://docs.rs/typex_derive). Enable the `derive` feature
//! to use them as [`Meta`] and [`MetaMut`].
//!
//! ## Structural equality
//!
//! [`Meta::eq_dyn`] compares values with matching runtime type metadata. Its
//! default implementation dispatches on the shape from [`Meta::reflect`]:
//!
//! - [`Reflect::Struct`] compares field names, then fields by name.
//! - [`Reflect::Tuple`] compares lengths, then fields by index.
//! - [`Reflect::Enum`] compares active variant names, then their fields by
//! name or index.
//! - [`Reflect::Map`] compares lengths, then looks up each visited key by
//! string. It supports `String` and `&'static str` keys.
//! - [`Reflect::Sequence`] and [`Reflect::KeyedSequence`] compare lengths,
//! then items by index.
//! - [`Reflect::Option`] compares presence and inner values.
//! - [`Reflect::Scalar`] returns `false`; scalar implementations provide
//! their own value comparisons.
//!
//! Built-in scalars, tuples, `Result` and the derives compare values directly,
//! avoiding dispatch through the access traits. `BTreeMap` and `HashMap`
//! compare native keys and reflective values. Custom opaque values provide
//! equality through `#[typex(partial_eq)]` or a hand-written implementation.
//! Float equality follows `PartialEq`, so `NaN != NaN`.
//!
//! ## Feature flags
//!
//! - `std` (default): Enables `HashMap` support and implementations of
//! `std::error::Error` for the crate's error types
//! - `derive`: Re-exports the [`Meta`] and [`MetaMut`] derive macros
//!
//! ## Minimum supported Rust version (MSRV)
//!
//! Rust v1.85+ is required.
//!
//! ## Example
//!
//! ```rust
//! use typex::{Meta, Object, ObjectOps};
//!
//! #[derive(Clone, Debug, Meta)]
//! struct Scope {
//! name: &'static str,
//! }
//!
//! #[derive(Debug, Meta)]
//! struct User {
//! id: u16,
//! scopes: Vec<Scope>,
//! }
//!
//! let object = Object::new(User {
//! id: 42,
//! scopes: vec![Scope { name: "read" }],
//! });
//!
//! assert!(object.is::<User>());
//! assert_eq!(object.type_name(), core::any::type_name::<User>());
//! assert_eq!(object.field_names(), &["id", "scopes"]);
//!
//! assert_eq!(object.field("id").unwrap().to_ref::<u16>(), Some(&42));
//!
//! let scope_name = |object: &Object| {
//! object
//! .field("scopes")?
//! .item(0)?
//! .field("name")?
//! .to_ref::<&'static str>()
//! .copied()
//! };
//! assert_eq!(scope_name(&object), Some("read"));
//!
//! // Use typed paths to traverse fields without an explicit downcast
//! assert_eq!(object.field_path(User::FIELD_ID.path()), Some(&42));
//! assert_eq!(
//! object.field_path(User::FIELD_SCOPES.item(0).then(Scope::FIELD_NAME)),
//! Some(&"read")
//! );
//! ```
extern crate alloc;
extern crate self as typex;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use TypeInfo;
pub use *;
pub use ;