Struct inkwell::types::StructType
source · 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_alignment(self) -> IntValue<'ctx>
pub fn get_alignment(self) -> IntValue<'ctx>
Gets the alignment 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 struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
let struct_type_alignment = struct_type.get_alignment();
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>
pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx>
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(any(
feature = "llvm4-0",
feature = "llvm5-0",
feature = "llvm6-0",
feature = "llvm7-0",
feature = "llvm8-0",
feature = "llvm9-0",
feature = "llvm10-0",
feature = "llvm11-0",
feature = "llvm12-0",
feature = "llvm13-0",
feature = "llvm14-0"
))]
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 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>
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 moresource§impl<'ctx> Debug for StructType<'ctx>
impl<'ctx> Debug for StructType<'ctx>
source§impl Display for StructType<'_>
impl Display for StructType<'_>
source§impl<'ctx> From<StructType<'ctx>> for AnyTypeEnum<'ctx>
impl<'ctx> From<StructType<'ctx>> for AnyTypeEnum<'ctx>
source§fn from(value: StructType<'_>) -> AnyTypeEnum<'_>
fn from(value: StructType<'_>) -> AnyTypeEnum<'_>
source§impl<'ctx> From<StructType<'ctx>> for BasicMetadataTypeEnum<'ctx>
impl<'ctx> From<StructType<'ctx>> for BasicMetadataTypeEnum<'ctx>
source§fn from(value: StructType<'_>) -> BasicMetadataTypeEnum<'_>
fn from(value: StructType<'_>) -> BasicMetadataTypeEnum<'_>
source§impl<'ctx> From<StructType<'ctx>> for BasicTypeEnum<'ctx>
impl<'ctx> From<StructType<'ctx>> for BasicTypeEnum<'ctx>
source§fn from(value: StructType<'_>) -> BasicTypeEnum<'_>
fn from(value: StructType<'_>) -> BasicTypeEnum<'_>
source§impl<'ctx> PartialEq for StructType<'ctx>
impl<'ctx> PartialEq for StructType<'ctx>
source§fn eq(&self, other: &StructType<'ctx>) -> bool
fn eq(&self, other: &StructType<'ctx>) -> bool
self
and other
values to be equal, and is used
by ==
.