🔮 Bronzite
Compile-time type reflection for Rust ✨
🪄 Ever wished you could inspect types, traits, and method bodies at compile time? Now you can!
Bronzite lets your proc-macros see everything about your types - trait implementations, field names, method signatures, even the source code of method bodies. All at compile time. 🚀
🌟 Features
- 🔍 Discover trait implementations - Find out what traits a type implements
- 📋 Inspect struct fields - Get field names, types, and visibility
- 🔧 Examine methods - See method signatures and even their bodies
- 🔗 Resolve type aliases - Follow the chain to the underlying type
- ⚡ Fast & cached - A background daemon caches compilation results
- 🤝 Proc-macro friendly - Designed to be used from your own macros
📦 Installation
# Install the daemon and tools
# Make sure you have the required nightly toolchain
🚀 Quick Start
Using in Your Proc-Macro
use ;
Using the Built-in Macros
use ;
// 🎯 Get all traits implemented by a type
const USER_TRAITS: & = bronzite_trait_names!;
// 📝 Get all field names of a struct
const USER_FIELDS: & = bronzite_field_names!;
🏗️ Architecture
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Your Proc- │────▶│ bronzite-daemon │────▶│ bronzite-query │
│ Macro │ │ (cached) │ │ (rustc plugin) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ Unix Socket │ Compiles & │
│ IPC 🔌 │ Extracts 📊 │
▼ ▼ ▼
TokenStream Type Info Cache rustc Internals
- 🔌 bronzite-client - Your proc-macro connects to the daemon
- 🏠 bronzite-daemon - Background service that caches compilation
- 🔬 bronzite-query - Rustc plugin that extracts type information
- 📦 bronzite-types - Shared protocol types
📚 Available Queries
| Query | Description |
|---|---|
get_trait_impls |
🔗 Get all trait implementations for a type |
get_inherent_impls |
🔧 Get inherent impl blocks (impl Foo { ... }) |
get_fields |
📋 Get struct/enum fields |
get_type |
📖 Get detailed type information |
get_traits |
📚 List all traits in a crate |
get_trait |
🔍 Get detailed trait information |
check_impl |
✅ Check if a type implements a trait |
resolve_alias |
🔗 Resolve type aliases |
find_types |
🔎 Find types matching a pattern |
get_layout |
📐 Get memory layout information |
🎮 Example
Check out the examples/ directory for a complete working example:
# Start the daemon pointing at the types crate
&
# Run the example app
&&
Output:
=== Bronzite Compile-Time Reflection Demo ===
Traits implemented by User (discovered at compile time):
- Debug
- Clone
- Serialize
- HasId
Methods on User (discovered at compile time):
- new()
- deactivate()
- is_active()
=== Demo Complete ===
⚙️ How It Works
- 🚀 When your proc-macro runs, it calls
connect_or_start() - 🏠 This ensures a bronzite-daemon is running (starts one if needed)
- 📬 Your query is sent to the daemon over a Unix socket
- 🔨 The daemon compiles your target crate using a special rustc plugin
- 📊 Type information is extracted and cached
- 📨 Results are returned to your proc-macro
- ✨ You generate code based on the reflection data!
🔧 Requirements
- Rust nightly-2025-08-20 - Required for the rustc plugin (the daemon handles this automatically)
- Unix-like OS - Uses Unix sockets for IPC (macOS, Linux)
🤔 Why "Bronzite"?
Bronzite is a mineral known for its reflective, bronze-like sheen. Just like how bronzite reflects light, this crate reflects your types! 🪨✨
📄 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.
🤝 Contributing
Contributions are welcome! Feel free to:
- 🐛 Report bugs
- 💡 Suggest features
- 🔧 Submit PRs
Made with 💜 and a lot of ☕