pub struct StructType<'ctx> { /* private fields */ }Expand description
A StructType is the type of a heterogeneous container of types.
Implementations§
Source§impl<'ctx> StructType<'ctx>
impl<'ctx> StructType<'ctx>
Sourcepub unsafe fn new(struct_type: LLVMTypeRef) -> Self
pub unsafe fn new(struct_type: LLVMTypeRef) -> Self
Sourcepub fn get_field_type_at_index(self, index: u32) -> Option<BasicTypeEnum<'ctx>>
pub fn get_field_type_at_index(self, index: u32) -> Option<BasicTypeEnum<'ctx>>
Gets the type of a field belonging to this StructType.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into()], false);
assert_eq!(struct_type.get_field_type_at_index(0).unwrap().into_float_type(), f32_type);Sourcepub unsafe fn get_field_type_at_index_unchecked(
self,
index: u32,
) -> BasicTypeEnum<'ctx>
pub unsafe fn get_field_type_at_index_unchecked( self, index: u32, ) -> BasicTypeEnum<'ctx>
Gets the type of a field belonging to this StructType.
§Safety
The index must be less than StructType::count_fields and the struct must not be opaque.
Sourcepub fn const_named_struct(
self,
values: &[BasicValueEnum<'ctx>],
) -> StructValue<'ctx>
pub fn const_named_struct( self, values: &[BasicValueEnum<'ctx>], ) -> StructValue<'ctx>
Creates a StructValue based on this StructType’s definition.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let f32_zero = f32_type.const_float(0.);
let struct_type = context.struct_type(&[f32_type.into()], false);
let struct_val = struct_type.const_named_struct(&[f32_zero.into()]);Sourcepub fn const_zero(self) -> StructValue<'ctx>
pub fn const_zero(self) -> StructValue<'ctx>
Creates a constant zero value of this StructType.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
let struct_zero = struct_type.const_zero();Sourcepub fn size_of(self) -> Option<IntValue<'ctx>>
pub fn size_of(self) -> Option<IntValue<'ctx>>
Gets the size of this StructType. Value may vary depending on the target architecture.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let f32_struct_type = context.struct_type(&[f32_type.into()], false);
let f32_struct_type_size = f32_struct_type.size_of();Sourcepub fn get_context(self) -> ContextRef<'ctx>
pub fn get_context(self) -> ContextRef<'ctx>
Gets a reference to the Context this StructType was created in.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
assert_eq!(struct_type.get_context(), context);Sourcepub fn get_name(&self) -> Option<&CStr>
pub fn get_name(&self) -> Option<&CStr>
Gets this StructType’s name.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.opaque_struct_type("opaque_struct");
assert_eq!(struct_type.get_name().unwrap().to_str().unwrap(), "opaque_struct");Sourcepub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx>
👎Deprecated: Starting from version 15.0, LLVM doesn’t differentiate between pointer types. Use Context::ptr_type instead.
pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx>
Starting from version 15.0, LLVM doesn’t differentiate between pointer types. Use Context::ptr_type instead.
Creates a PointerType with this StructType for its element type.
§Example
use inkwell::AddressSpace;
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
let struct_ptr_type = struct_type.ptr_type(AddressSpace::default());
#[cfg(feature = "typed-pointers")]
assert_eq!(struct_ptr_type.get_element_type().into_struct_type(), struct_type);Sourcepub fn fn_type(
self,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_args: bool,
) -> FunctionType<'ctx>
pub fn fn_type( self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool, ) -> FunctionType<'ctx>
Creates a FunctionType with this StructType for its return type.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
let fn_type = struct_type.fn_type(&[], false);Sourcepub fn array_type(self, size: u32) -> ArrayType<'ctx>
pub fn array_type(self, size: u32) -> ArrayType<'ctx>
Creates an ArrayType with this StructType for its element type.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
let struct_array_type = struct_type.array_type(3);
assert_eq!(struct_array_type.len(), 3);
assert_eq!(struct_array_type.get_element_type().into_struct_type(), struct_type);Sourcepub fn is_packed(self) -> bool
pub fn is_packed(self) -> bool
Determines whether or not a StructType is packed.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
assert!(struct_type.is_packed());Sourcepub fn is_opaque(self) -> bool
pub fn is_opaque(self) -> bool
Determines whether or not a StructType is opaque.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.opaque_struct_type("opaque_struct");
assert!(struct_type.is_opaque());Sourcepub fn count_fields(self) -> u32
pub fn count_fields(self) -> u32
Counts the number of field types.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let i8_type = context.i8_type();
let struct_type = context.struct_type(&[f32_type.into(), i8_type.into()], false);
assert_eq!(struct_type.count_fields(), 2);Sourcepub fn get_field_types(self) -> Vec<BasicTypeEnum<'ctx>>
pub fn get_field_types(self) -> Vec<BasicTypeEnum<'ctx>>
Gets this StructType’s field types.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let i8_type = context.i8_type();
let struct_type = context.struct_type(&[f32_type.into(), i8_type.into()], false);
assert_eq!(struct_type.get_field_types(), &[f32_type.into(), i8_type.into()]);Sourcepub fn get_field_types_iter(self) -> FieldTypesIter<'ctx> ⓘ
pub fn get_field_types_iter(self) -> FieldTypesIter<'ctx> ⓘ
Get a struct field iterator.
Sourcepub fn print_to_string(self) -> LLVMString
pub fn print_to_string(self) -> LLVMString
Print the definition of a StructType to LLVMString.
Sourcepub fn get_undef(self) -> StructValue<'ctx>
pub fn get_undef(self) -> StructValue<'ctx>
Creates an undefined instance of a StructType.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let i8_type = context.i8_type();
let struct_type = context.struct_type(&[f32_type.into(), i8_type.into()], false);
let struct_type_undef = struct_type.get_undef();
assert!(struct_type_undef.is_undef());Sourcepub fn get_poison(self) -> StructValue<'ctx>
pub fn get_poison(self) -> StructValue<'ctx>
Creates a poison instance of a StructType.
§Example
use inkwell::context::Context;
use inkwell::values::AnyValue;
let context = Context::create();
let f32_type = context.f32_type();
let i8_type = context.i8_type();
let struct_type = context.struct_type(&[f32_type.into(), i8_type.into()], false);
let struct_type_poison = struct_type.get_poison();
assert!(struct_type_poison.is_poison());Sourcepub fn set_body(self, field_types: &[BasicTypeEnum<'ctx>], packed: bool) -> bool
pub fn set_body(self, field_types: &[BasicTypeEnum<'ctx>], packed: bool) -> bool
Defines the body of a StructType.
If the struct is an opaque type, it will no longer be after this call.
Resetting the packed state of a non-opaque struct type may not work.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let opaque_struct_type = context.opaque_struct_type("opaque_struct");
opaque_struct_type.set_body(&[f32_type.into()], false);
assert!(!opaque_struct_type.is_opaque());Sourcepub fn const_array(self, values: &[StructValue<'ctx>]) -> ArrayValue<'ctx>
pub fn const_array(self, values: &[StructValue<'ctx>]) -> ArrayValue<'ctx>
Creates a constant ArrayValue.
§Example
use inkwell::context::Context;
let context = Context::create();
let f32_type = context.f32_type();
let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
let struct_val = struct_type.const_named_struct(&[]);
let struct_array = struct_type.const_array(&[struct_val, struct_val]);
assert!(struct_array.is_const());Trait Implementations§
Source§impl<'ctx> AnyType<'ctx> for StructType<'ctx>
impl<'ctx> AnyType<'ctx> for StructType<'ctx>
Source§fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>
fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>
AnyTypeEnum that represents the current type.Source§fn print_to_string(&self) -> LLVMString
fn print_to_string(&self) -> LLVMString
LLVMString.Source§impl AsTypeRef for StructType<'_>
impl AsTypeRef for StructType<'_>
Source§fn as_type_ref(&self) -> LLVMTypeRef
fn as_type_ref(&self) -> LLVMTypeRef
Source§impl<'ctx> BasicType<'ctx> for StructType<'ctx>
impl<'ctx> BasicType<'ctx> for StructType<'ctx>
Source§fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>
fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>
BasicTypeEnum that represents the current type.Source§fn fn_type(
&self,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_args: bool,
) -> FunctionType<'ctx>
fn fn_type( &self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool, ) -> FunctionType<'ctx>
Source§fn is_sized(&self) -> bool
fn is_sized(&self) -> bool
BasicType is sized or not.
For example, opaque structs are unsized. Read moreSource§fn size_of(&self) -> Option<IntValue<'ctx>>
fn size_of(&self) -> Option<IntValue<'ctx>>
BasicType. Value may vary depending on the target architecture. Read moreSource§fn get_alignment(&self) -> IntValue<'ctx>
fn get_alignment(&self) -> IntValue<'ctx>
BasicType. Value may vary depending on the target architecture. Read moreSource§fn array_type(&self, size: u32) -> ArrayType<'ctx>
fn array_type(&self, size: u32) -> ArrayType<'ctx>
Source§fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx>
fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx>
Starting from version 15.0, LLVM doesn’t differentiate between pointer types. Use Context::ptr_type instead.
Source§impl<'ctx> Clone for StructType<'ctx>
impl<'ctx> Clone for StructType<'ctx>
Source§fn clone(&self) -> StructType<'ctx>
fn clone(&self) -> StructType<'ctx>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more