pub struct StructDef {
pub name: String,
pub path: String,
pub generics: Vec<GenericParam>,
/* private fields */
}Expand description
A reflected struct definition with navigation methods.
Provides access to struct metadata and navigation to related types like fields, trait implementations, and methods.
ยงExample
use bronzite_client::Crate;
let krate = Crate::reflect("my_crate")?;
let user = krate.get_struct("User")?;
// Get fields
for field in user.fields()? {
println!("Field: {} of type {}",
field.name.unwrap_or_default(),
field.ty
);
}
// Check trait implementation
if user.implements("Debug")? {
println!("User implements Debug");
}
// Get methods
for method in user.methods()? {
println!("Method: {}", method.name);
}Fieldsยง
ยงname: StringThe structโs name (without path)
path: StringThe structโs full path
generics: Vec<GenericParam>Generic parameters
Implementationsยง
Sourceยงimpl StructDef
impl StructDef
Sourcepub fn fields(&self) -> Result<Vec<Field>>
pub fn fields(&self) -> Result<Vec<Field>>
Get all fields of this struct.
Returns a vector of Field objects, each representing a field in the struct.
Fields include metadata like name, type, visibility, size, and offset.
ยงExample
let user = krate.get_struct("User")?;
for field in user.fields()? {
println!("Field: {} of type {}",
field.name.as_deref().unwrap_or("<unnamed>"),
field.ty
);
if let Some(size) = field.size {
println!(" Size: {} bytes", size);
}
}Sourcepub fn trait_impls(&self) -> Result<Vec<TraitImpl>>
pub fn trait_impls(&self) -> Result<Vec<TraitImpl>>
Get all trait implementations for this struct.
Returns a vector of TraitImpl objects containing information about each
trait implementation, including methods, associated types, and source code.
ยงExample
let user = krate.get_struct("User")?;
for impl_block in user.trait_impls()? {
println!("Implements: {}", impl_block.trait_path);
for method in impl_block.methods() {
println!(" - {}", method.name);
}
}Sourcepub fn implements(&self, trait_path: &str) -> Result<bool>
pub fn implements(&self, trait_path: &str) -> Result<bool>
Check if this struct implements a specific trait.
This is a convenient way to test for trait implementation without fetching all trait impls.
ยงArguments
trait_path- The trait path to check (e.g., โDebugโ, โstd::fmt::Displayโ)
ยงExample
let user = krate.get_struct("User")?;
if user.implements("Debug")? {
println!("User can be debug-printed");
}
if user.implements("std::clone::Clone")? {
println!("User can be cloned");
}Sourcepub fn methods(&self) -> Result<Vec<Method>>
pub fn methods(&self) -> Result<Vec<Method>>
Get inherent methods (from impl StructName { ... } blocks).
Returns methods defined in inherent impl blocks, not trait implementations.
Each Method includes the signature, body source, and navigation to
parameter/return types.
ยงExample
let user = krate.get_struct("User")?;
for method in user.methods()? {
println!("Method: {}", method.signature);
if let Some(body) = &method.body_source {
println!(" Implementation: {}", body);
}
if let Some(ret_type) = method.return_type_def()? {
println!(" Returns: {}", ret_type.name());
}
}Sourcepub fn layout(&self) -> Result<LayoutInfo>
pub fn layout(&self) -> Result<LayoutInfo>
Get memory layout information for this struct.
Returns LayoutInfo containing size, alignment, field offsets,
and auto-trait implementations (Send, Sync, Copy).
ยงExample
let user = krate.get_struct("User")?;
let layout = user.layout()?;
println!("Size: {} bytes", layout.size);
println!("Alignment: {} bytes", layout.align);
println!("Is Copy: {}", layout.is_copy);Sourcepub fn details(&self) -> Option<&TypeDetails>
pub fn details(&self) -> Option<&TypeDetails>
Get detailed type information.
Sourcepub fn visibility(&self) -> Option<&Visibility>
pub fn visibility(&self) -> Option<&Visibility>
Get visibility of this struct.