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§
Source§impl Field
impl Field
Sourcepub fn type_def(&self) -> Result<Option<Item>>
pub fn type_def(&self) -> Result<Option<Item>>
Navigate to the type definition for this field’s type.
Returns an Item representing the field’s type definition, if it
can be resolved. Returns None for primitive types or external types
not in the queried crate.
§Example
ⓘ
let user = krate.get_struct("User")?;
for field in user.fields()? {
if let Some(field_type) = field.type_def()? {
match field_type {
Item::Struct(s) => println!("{} is a struct", field.name.unwrap()),
Item::Enum(e) => println!("{} is an enum", field.name.unwrap()),
_ => {}
}
}
}§Returns
Ok(Some(Item))- The type definition was foundOk(None)- The type is primitive or externalErr(_)- An error occurred querying the daemon
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