rustbinary/reflection.rs
1/// Description of one struct, tuple, or enum-variant field.
2#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3pub struct FieldInfo {
4 /// Declared field name, or its tuple index.
5 pub name: &'static str,
6 /// Canonical token representation of the declared Rust type.
7 pub type_name: &'static str,
8 /// Zero-based declaration index.
9 pub index: usize,
10}
11
12/// Description of one enum variant.
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
14pub struct VariantInfo {
15 /// Declared variant name.
16 pub name: &'static str,
17 /// Zero-based discriminant used by the default Serde representation.
18 pub index: usize,
19 /// Variant fields in declaration order.
20 pub fields: &'static [FieldInfo],
21}
22
23/// Static structural shape generated for a reflected type.
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25pub enum TypeShape {
26 /// A struct or tuple struct.
27 Struct(&'static [FieldInfo]),
28 /// An enum and all its variants.
29 Enum(&'static [VariantInfo]),
30}
31
32/// Compile-time structural reflection without runtime registration or allocation.
33pub trait Reflect {
34 /// Fully qualified declared type name.
35 const TYPE_NAME: &'static str;
36 /// Static structural metadata.
37 const SHAPE: TypeShape;
38}