Struct inkwell::types::StructType[][src]

pub struct StructType<'ctx> { /* fields omitted */ }
Expand description

A StructType is the type of a heterogeneous container of types.

Implementations

This is supported on crate features llvm3-7 or llvm3-8 or llvm3-9 or llvm4-0 or llvm5-0 or llvm6-0 or llvm7-0 or llvm8-0 or llvm9-0 or llvm10-0 or llvm11-0 or llvm12-0 only.

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);

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()]);

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();

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();

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();

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);

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");

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::Generic);

assert_eq!(struct_ptr_type.get_element_type().into_struct_type(), struct_type);

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);

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);

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());

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());

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);

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()]);

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());

Defines the body of an opaue StructType.

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());

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

Returns an AnyTypeEnum that represents the current type.

Prints the definition of a Type to a LLVMString.

Returns a BasicTypeEnum that represents the current type.

Create a FunctionType with this BasicType as its return type. Read more

Determines whether or not this BasicType is sized or not. For example, opaque structs are unsized. Read more

Gets the size of this BasicType. Value may vary depending on the target architecture. Read more

Create an ArrayType with this BasicType as its elements. Read more

Create a PointerType that points to this BasicType. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.