| Crates.io | quarry |
| lib.rs | quarry |
| version | 0.2.0 |
| created_at | 2025-08-05 14:18:31.486425+00 |
| updated_at | 2025-08-10 15:30:45.806722+00 |
| description | Quarry is a Rust library for mining type information from the Rust standard library. |
| homepage | |
| repository | https://github.com/richwill28/quarry |
| max_upload_size | |
| id | 1782054 |
| size | 116,522 |
Quarry is a Rust library for mining type information from the Rust standard library. It provides access to struct field information, including private fields, by analyzing the actual standard library installed on your system.
Note: The API is currently unstable.
Current Focus: Quarry currently analyzes structs only. Popular types like Option<T> and Result<T, E> (which are enums) cannot be analyzed yet.
Planned Features: Support for enums, traits, and other types is planned for future releases. If you need enum analysis immediately, consider using rustdoc directly.
Quarry dynamically analyzes the Rust standard library installed on your system to extract detailed information about structs, including:
To use the full functionality of Quarry, you need:
Nightly Rust toolchain (for rustdoc JSON generation):
rustup toolchain install nightly
Rust source code (for analyzing the standard library):
rustup component add rust-src --toolchain nightly
Add this to your Cargo.toml:
[dependencies]
quarry = "0.1.0"
use quarry::mine_struct_info;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Analyze alloc::string::String (requires full module path)
let result = mine_struct_info("alloc::string::String")?;
println!("Struct: {}", result.name);
println!("Simple name: {}", result.simple_name);
println!("Module path: {}", result.module_path);
// Print fields (including private fields)
for field in result.fields {
println!(" {} -> {} (public: {})",
field.name, field.type_name, field.is_public);
}
Ok(())
}
Quarry requires explicit, full module paths to ensure unambiguous type resolution:
// ✅ Correct usage - full module paths
let string_info = mine_struct_info("alloc::string::String")?;
let vec_info = mine_struct_info("alloc::vec::Vec")?;
let hashmap_info = mine_struct_info("std::collections::HashMap")?;
// ❌ Incorrect usage - will fail
let result = mine_struct_info("String"); // Error: requires full path
let result = mine_struct_info("Vec"); // Error: requires full path
Quarry caches the analyzed standard library information for performance:
use quarry::{init_stdlib_cache, cache_stats, clear_stdlib_cache};
// Initialize cache explicitly (optional)
init_stdlib_cache()?;
// Check cache statistics
let (count, initialized) = cache_stats()?;
println!("Cache has {} types, initialized: {}", count, initialized);
// Clear cache if needed
clear_stdlib_cache();
use quarry::list_stdlib_structs;
// Get all available standard library struct types
let structs = list_stdlib_structs()?;
for struct_name in structs {
println!("{}", struct_name);
}
use quarry::is_stdlib_struct;
// Quick check if a type exists in the standard library
if is_stdlib_struct("alloc::string::String") {
println!("String is available in the standard library");
}
Quarry includes comprehensive debug logging throughout the analysis pipeline. This is especially useful for understanding what's happening during cache initialization, type lookup, and rustdoc generation.
Quarry uses the standard log crate for logging. To see debug output, add env_logger to your dependencies and initialize it:
[dependencies]
env_logger = "0.11"
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the logger to see debug output
env_logger::init();
// Your code here...
}
Then run your application with the RUST_LOG environment variable:
# See all debug logs
RUST_LOG=debug cargo run
# See only Quarry debug logs
RUST_LOG=quarry=debug cargo run
# See only standard library module logs
RUST_LOG=quarry::stdlib=debug cargo run
Quarry includes comprehensive examples that demonstrate its capabilities:
cargo run --example basic_usage
Shows fundamental usage including:
cargo run --example advanced_usage
Demonstrates advanced features including:
Both examples can be run with debug logging:
RUST_LOG=quarry=debug cargo run --example basic_usage
RUST_LOG=quarry=debug cargo run --example advanced_usage
Quarry uses the following approach:
rustdoc to analyze the actual standard library source code installed on your systemrustdoc JSON output directly to extract struct information including private fields┌─────────────────┐
│ Your Code │ mine_struct_info("alloc::string::String")
└─────────────────┘
│
▼
┌─────────────────┐
│ Quarry │ First call: run cargo doc → parse JSON → populate cache
│ (Public API) │ Subsequent calls: direct lookup in cache
└─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐
│ Memory Cache │ │ Standard Library│
│ (HashMap) │ │ Source Code │
│ "alloc::string │ │ (rust-src) │
│ ::String" → ... │ └─────────────────┘
└─────────────────┘ │
▼
┌─────────────────┐
│ cargo doc │
│ --output-format │
│ json │
└─────────────────┘
Quarry provides detailed error information:
TypeNotFound: The requested type was not found in the standard libraryNotAStruct: The requested type exists but is not a structStdlibAnalysis: Failed to generate or parse rustdoc JSON (usually due to missing nightly toolchain or rust-src)Io: File system or process execution errorsContributions are welcome! Please feel free to submit an issue or a pull request.
MIT License - see LICENSE file for details.