Skip to content

Commit 897fd3f

Browse files
author
Grégoire Geis
committed
Slightly improved docs and structure of *Type traits
1 parent 46cbe4f commit 897fd3f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/types/traits.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,27 @@ pub trait AsTypeRef {
1414

1515
macro_rules! trait_type_set {
1616
($trait_name:ident: $($args:ident),*) => (
17-
pub trait $trait_name: AsTypeRef + Debug {}
18-
1917
$(
2018
impl $trait_name for $args {}
2119
)*
2220
);
2321
}
2422

23+
/// Represents any LLVM type.
24+
pub trait AnyType: AsTypeRef + Debug {
25+
/// Returns an `AnyTypeEnum` that represents the current type.
26+
fn as_any_type_enum(&self) -> AnyTypeEnum {
27+
AnyTypeEnum::new(self.as_type_ref())
28+
}
29+
}
30+
31+
/// Represents a basic LLVM type, that may be used in functions and struct declarations.
32+
pub trait BasicType: AnyType {
33+
/// Returns a `BasicTypeEnum` that represents the current type.
34+
fn as_basic_type_enum(&self) -> BasicTypeEnum {
35+
BasicTypeEnum::new(self.as_type_ref())
36+
}
37+
}
38+
2539
trait_type_set! {AnyType: AnyTypeEnum, BasicTypeEnum, IntType, FunctionType, FloatType, PointerType, StructType, ArrayType, VoidType, VectorType}
2640
trait_type_set! {BasicType: BasicTypeEnum, IntType, FloatType, PointerType, StructType, ArrayType, VectorType}

0 commit comments

Comments
 (0)