pub struct Field {
pub name: Option<String>,
pub index: usize,
pub ty: String,
pub resolved_ty: Option<String>,
pub visibility: Visibility,
pub docs: Option<String>,
pub offset: Option<usize>,
pub size: Option<usize>,
/* private fields */
}Expand description
A field of a struct, enum variant, or union.
Provides field metadata and the ability to navigate to the field’s type definition.
§Example
ⓘ
let user = krate.get_struct("User")?;
for field in user.fields()? {
println!("Field: {}", field.name.as_deref().unwrap_or("<unnamed>"));
println!(" Type: {}", field.ty);
println!(" Size: {:?}", field.size);
// Navigate to the field's type definition
if let Some(field_type) = field.type_def()? {
println!(" Defined in: {}", field_type.path());
}
}Fields§
§name: Option<String>Field name (None for tuple struct fields)
index: usizeField index in the struct
ty: StringType as a string
resolved_ty: Option<String>Resolved type (following aliases)
visibility: VisibilityField visibility
docs: Option<String>Doc comments
offset: Option<usize>Offset in bytes (if layout is known)
size: Option<usize>Size in bytes (if layout is known)
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Field
impl RefUnwindSafe for Field
impl Send for Field
impl Sync for Field
impl Unpin for Field
impl UnwindSafe for Field
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more