Struct Type

Source
pub struct Type<'tu> { /* private fields */ }
Expand description

The type of an AST entity.

Implementations§

Source§

impl<'tu> Type<'tu>

Source

pub fn get_kind(&self) -> TypeKind

Returns the kind of this type.

Source

pub fn get_display_name(&self) -> String

Returns the display name of this type.

Source

pub fn get_alignof(&self) -> Result<usize, AlignofError>

Returns the alignment of this type in bytes.

§Failures
  • this type is a dependent type
  • this type is an incomplete type
Source

pub fn get_offsetof<F: AsRef<str>>( &self, field: F, ) -> Result<usize, OffsetofError>

Returns the offset of the field with the supplied name in this record type in bits.

§Failures
  • this record type is a dependent type
  • this record record type is an incomplete type
  • this record type does not contain a field with the supplied name
Examples found in repository?
examples/structs.rs (line 28)
5fn main() {
6    // Acquire an instance of `Clang`
7    let clang = Clang::new().unwrap();
8
9    // Create a new `Index`
10    let index = Index::new(&clang, false, false);
11
12    // Parse a source file into a translation unit
13    let tu = index.parser("examples/structs.c").parse().unwrap();
14
15    // Get the structs in this translation unit
16    let structs = tu.get_entity().get_children().into_iter().filter(|e| {
17        e.get_kind() == EntityKind::StructDecl
18    }).collect::<Vec<_>>();
19
20    // Print information about the structs
21    for struct_ in structs {
22        let type_ =  struct_.get_type().unwrap();
23        let size = type_.get_sizeof().unwrap();
24        println!("struct: {:?} (size: {} bytes)", struct_.get_name().unwrap(), size);
25
26        for field in struct_.get_children() {
27            let name = field.get_name().unwrap();
28            let offset = type_.get_offsetof(&name).unwrap();
29            println!("    field: {:?} (offset: {} bits)", name, offset);
30        }
31    }
32}
Source

pub fn get_sizeof(&self) -> Result<usize, SizeofError>

Returns the size of this type in bytes.

§Failures
  • this type is a dependent type
  • this type is an incomplete type
  • this type is a variable size type
Examples found in repository?
examples/structs.rs (line 23)
5fn main() {
6    // Acquire an instance of `Clang`
7    let clang = Clang::new().unwrap();
8
9    // Create a new `Index`
10    let index = Index::new(&clang, false, false);
11
12    // Parse a source file into a translation unit
13    let tu = index.parser("examples/structs.c").parse().unwrap();
14
15    // Get the structs in this translation unit
16    let structs = tu.get_entity().get_children().into_iter().filter(|e| {
17        e.get_kind() == EntityKind::StructDecl
18    }).collect::<Vec<_>>();
19
20    // Print information about the structs
21    for struct_ in structs {
22        let type_ =  struct_.get_type().unwrap();
23        let size = type_.get_sizeof().unwrap();
24        println!("struct: {:?} (size: {} bytes)", struct_.get_name().unwrap(), size);
25
26        for field in struct_.get_children() {
27            let name = field.get_name().unwrap();
28            let offset = type_.get_offsetof(&name).unwrap();
29            println!("    field: {:?} (offset: {} bits)", name, offset);
30        }
31    }
32}
Source

pub fn get_address_space(&self) -> usize

Returns the address space of this type.

Source

pub fn get_argument_types(&self) -> Option<Vec<Type<'tu>>>

Returns the argument types for this function or method type, if applicable.

Source

pub fn get_calling_convention(&self) -> Option<CallingConvention>

Returns the calling convention specified for this function type, if applicable.

Source

pub fn get_canonical_type(&self) -> Type<'tu>

Returns the canonical type for this type.

The canonical type is the underlying type with all “sugar” removed (e.g., typedefs).

Source

pub fn get_class_type(&self) -> Option<Type<'tu>>

Returns the class type for this member pointer type, if applicable.

Source

pub fn get_declaration(&self) -> Option<Entity<'tu>>

Returns the AST entity that declared this type, if any.

Source

pub fn get_elaborated_type(&self) -> Option<Type<'tu>>

Returns the type named by this elaborated type, if applicable.

Source

pub fn get_element_type(&self) -> Option<Type<'tu>>

Returns the element type for this array, complex, or vector type, if applicable.

Source

pub fn get_exception_specification(&self) -> Option<ExceptionSpecification>

Returns the exception specification of this type, if applicable.

Source

pub fn get_fields(&self) -> Option<Vec<Entity<'tu>>>

Returns the fields in this record type, if applicable.

Source

pub fn get_modified_type(&self) -> Option<Type<'tu>>

Return the type that was modified by this attributed type.

Source

pub fn get_nullability(&self) -> Option<Nullability>

Returns the nullability of this pointer type, if applicable.

Source

pub fn get_objc_encoding(&self) -> Option<String>

Returns the encoding of this Objective-C type, if applicable.

Source

pub fn get_objc_object_base_type(&self) -> Option<Type<'_>>

Returns the base type of this Objective-C type, if applicable.

Source

pub fn get_objc_protocol_declarations(&self) -> Vec<Entity<'tu>>

Returns the declarations for all protocol references for this Objective-C type, if applicable.

Source

pub fn get_objc_type_arguments(&self) -> Vec<Type<'tu>>

Returns the type arguments for this Objective-C type, if applicable.

Source

pub fn get_pointee_type(&self) -> Option<Type<'tu>>

Returns the pointee type for this pointer type, if applicable.

Source

pub fn get_ref_qualifier(&self) -> Option<RefQualifier>

Returns the ref qualifier for this C++ function or method type, if applicable.

Source

pub fn get_result_type(&self) -> Option<Type<'tu>>

Returns the result type for this function or method type, if applicable.

Source

pub fn get_size(&self) -> Option<usize>

Returns the size of this constant array or vector type, if applicable.

Source

pub fn get_template_argument_types(&self) -> Option<Vec<Option<Type<'tu>>>>

Returns the template argument types for this template class specialization type, if applicable.

Source

pub fn get_typedef_name(&self) -> Option<String>

Returns the typedef name of this type, if applicable.

Source

pub fn is_const_qualified(&self) -> bool

Returns whether this type is qualified with const.

Source

pub fn is_elaborated(&self) -> Option<bool>

Returns whether this type is an elaborated type, if it can be determined for certain.

Source

pub fn is_pod(&self) -> bool

Returns whether this type is plain old data (POD).

Source

pub fn is_restrict_qualified(&self) -> bool

Returns whether this type is qualified with restrict.

Source

pub fn is_transparent_tag(&self) -> bool

Returns whether this type is a transparent tag typedef.

Source

pub fn is_variadic(&self) -> bool

Returns whether this type is a variadic function type.

Source

pub fn is_volatile_qualified(&self) -> bool

Returns whether this type is qualified with volatile.

Source

pub fn visit_fields<F: FnMut(Entity<'tu>) -> bool>(&self, f: F) -> Option<bool>

Visits the fields in this record type, returning None if this type is not a record type and returning Some(b) otherwise where b indicates whether visitation was ended by the callback returning false.

Source

pub fn is_integer(&self) -> bool

Returns whether this type is an integer type.

Source

pub fn is_signed_integer(&self) -> bool

Returns whether this type is a signed integer type.

Source

pub fn is_unsigned_integer(&self) -> bool

Returns whether this type is an unsigned integer type.

Trait Implementations§

Source§

impl<'tu> Clone for Type<'tu>

Source§

fn clone(&self) -> Type<'tu>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tu> Debug for Type<'tu>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'tu> PartialEq for Type<'tu>

Source§

fn eq(&self, other: &Type<'tu>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'tu> Copy for Type<'tu>

Source§

impl<'tu> Eq for Type<'tu>

Auto Trait Implementations§

§

impl<'tu> Freeze for Type<'tu>

§

impl<'tu> RefUnwindSafe for Type<'tu>

§

impl<'tu> !Send for Type<'tu>

§

impl<'tu> !Sync for Type<'tu>

§

impl<'tu> Unpin for Type<'tu>

§

impl<'tu> UnwindSafe for Type<'tu>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.