pub struct Attribute { /* private fields */ }
Expand description

Functions, function parameters, and return types can have Attributes to indicate how they should be treated by optimizations and code generation.

Implementations§

source§

impl Attribute

source

pub unsafe fn new(attribute: LLVMAttributeRef) -> Self

Creates a new Attribute from a raw pointer.

source

pub fn as_mut_ptr(&self) -> LLVMAttributeRef

Acquires the underlying raw pointer belonging to this Attribute type.

source

pub fn is_enum(self) -> bool

Determines whether or not an Attribute is an enum. This method will likely be removed in the future in favor of Attributes being generically defined.

§Example
use inkwell::context::Context;

let context = Context::create();
let enum_attribute = context.create_enum_attribute(0, 10);

assert!(enum_attribute.is_enum());
source

pub fn is_string(self) -> bool

Determines whether or not an Attribute is a string. This method will likely be removed in the future in favor of Attributes being generically defined.

§Example
use inkwell::context::Context;

let context = Context::create();
let string_attribute = context.create_string_attribute("my_key_123", "my_val");

assert!(string_attribute.is_string());
source

pub fn is_type(self) -> bool

Determines whether or not an Attribute is a type attribute. This method will likely be removed in the future in favor of Attributes being generically defined.

§Example
use inkwell::context::Context;
use inkwell::attributes::Attribute;

let context = Context::create();
let kind_id = Attribute::get_named_enum_kind_id("sret");
let type_attribute = context.create_type_attribute(
    kind_id,
    context.i32_type().into(),
);

assert!(type_attribute.is_type());
source

pub fn get_named_enum_kind_id(name: &str) -> u32

Gets the enum kind id associated with a builtin name.

§Example
use inkwell::attributes::Attribute;

// This kind id doesn't exist:
assert_eq!(Attribute::get_named_enum_kind_id("foobar"), 0);

// These are real kind ids:
assert_eq!(Attribute::get_named_enum_kind_id("align"), 1);
assert_eq!(Attribute::get_named_enum_kind_id("builtin"), 5);
source

pub fn get_enum_kind_id(self) -> u32

Gets the kind id associated with an enum Attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let enum_attribute = context.create_enum_attribute(0, 10);

assert_eq!(enum_attribute.get_enum_kind_id(), 0);

This function also works for type Attributes.

use inkwell::context::Context;
use inkwell::attributes::Attribute;
use inkwell::types::AnyType;

let context = Context::create();
let kind_id = Attribute::get_named_enum_kind_id("sret");
let any_type = context.i32_type().as_any_type_enum();
let type_attribute = context.create_type_attribute(
    kind_id,
    any_type,
);

assert_eq!(type_attribute.get_enum_kind_id(), kind_id);
source

pub fn get_last_enum_kind_id() -> u32

Gets the last enum kind id associated with builtin names.

§Example
use inkwell::attributes::Attribute;

assert_eq!(Attribute::get_last_enum_kind_id(), 56);
source

pub fn get_enum_value(self) -> u64

Gets the value associated with an enum Attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let enum_attribute = context.create_enum_attribute(0, 10);

assert_eq!(enum_attribute.get_enum_value(), 10);
source

pub fn get_string_kind_id(&self) -> &CStr

Gets the string kind id associated with a string attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let string_attribute = context.create_string_attribute("my_key", "my_val");

assert_eq!(string_attribute.get_string_kind_id().to_str(), Ok("my_key"));
source

pub fn get_string_value(&self) -> &CStr

Gets the string value associated with a string attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let string_attribute = context.create_string_attribute("my_key", "my_val");

assert_eq!(string_attribute.get_string_value().to_str(), Ok("my_val"));
source

pub fn get_type_value(&self) -> AnyTypeEnum<'_>

Gets the type associated with a type attribute.

§Example
use inkwell::context::Context;
use inkwell::attributes::Attribute;
use inkwell::types::AnyType;

let context = Context::create();
let kind_id = Attribute::get_named_enum_kind_id("sret");
let any_type = context.i32_type().as_any_type_enum();
let type_attribute = context.create_type_attribute(
    kind_id,
    any_type,
);

assert!(type_attribute.is_type());
assert_eq!(type_attribute.get_type_value(), any_type);
assert_ne!(type_attribute.get_type_value(), context.i64_type().as_any_type_enum());

Trait Implementations§

source§

impl Clone for Attribute

source§

fn clone(&self) -> Attribute

Returns a copy 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 Debug for Attribute

source§

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

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

impl PartialEq for Attribute

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Attribute

source§

impl Eq for Attribute

Auto Trait Implementations§

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> 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,

§

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>,

§

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>,

§

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.