pub struct Attribute { /* private fields */ }
Expand description
Functions, function parameters, and return types can have Attribute
s to indicate
how they should be treated by optimizations and code generation.
Implementations§
Source§impl Attribute
impl Attribute
Sourcepub unsafe fn new(attribute: LLVMAttributeRef) -> Self
pub unsafe fn new(attribute: LLVMAttributeRef) -> Self
Creates a new Attribute
from a raw pointer.
Sourcepub fn as_mut_ptr(&self) -> LLVMAttributeRef
pub fn as_mut_ptr(&self) -> LLVMAttributeRef
Acquires the underlying raw pointer belonging to this Attribute
type.
Sourcepub fn is_enum(self) -> bool
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 Attribute
s 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());
Sourcepub fn is_string(self) -> bool
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 Attribute
s 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());
Sourcepub fn is_type(self) -> bool
Available on crate features llvm12-0
or llvm13-0
or llvm14-0
or llvm15-0
or llvm16-0
or llvm17-0
or llvm18-0
only.
pub fn is_type(self) -> bool
llvm12-0
or llvm13-0
or llvm14-0
or llvm15-0
or llvm16-0
or llvm17-0
or llvm18-0
only.Determines whether or not an Attribute
is a type attribute. This method will
likely be removed in the future in favor of Attribute
s 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());
Sourcepub fn get_named_enum_kind_id(name: &str) -> u32
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);
Sourcepub fn get_enum_kind_id(self) -> u32
Available on crate features llvm12-0
or llvm13-0
or llvm14-0
or llvm15-0
or llvm16-0
or llvm17-0
or llvm18-0
only.
pub fn get_enum_kind_id(self) -> u32
llvm12-0
or llvm13-0
or llvm14-0
or llvm15-0
or llvm16-0
or llvm17-0
or llvm18-0
only.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 Attribute
s.
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);
Sourcepub fn get_last_enum_kind_id() -> u32
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);
Sourcepub fn get_enum_value(self) -> u64
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);
Sourcepub fn get_string_kind_id(&self) -> &CStr
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"));
Sourcepub fn get_string_value(&self) -> &CStr
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"));
Sourcepub fn get_type_value(&self) -> AnyTypeEnum<'_>
Available on crate features llvm12-0
or llvm13-0
or llvm14-0
or llvm15-0
or llvm16-0
or llvm17-0
or llvm18-0
only.
pub fn get_type_value(&self) -> AnyTypeEnum<'_>
llvm12-0
or llvm13-0
or llvm14-0
or llvm15-0
or llvm16-0
or llvm17-0
or llvm18-0
only.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§
impl Copy for Attribute
impl Eq for Attribute
Auto Trait Implementations§
impl Freeze for Attribute
impl RefUnwindSafe for Attribute
impl !Send for Attribute
impl !Sync for Attribute
impl Unpin for Attribute
impl UnwindSafe for Attribute
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more