inkwell/types/
metadata_type.rs1use llvm_sys::prelude::LLVMTypeRef;
2
3use crate::context::ContextRef;
4use crate::support::LLVMString;
5use crate::types::enums::BasicMetadataTypeEnum;
6use crate::types::traits::AsTypeRef;
7use crate::types::{FunctionType, Type};
8
9use std::fmt::{self, Display};
10
11#[derive(Debug, PartialEq, Eq, Clone, Copy)]
13pub struct MetadataType<'ctx> {
14 metadata_type: Type<'ctx>,
15}
16
17impl<'ctx> MetadataType<'ctx> {
18 #[llvm_versions(6..)]
23 pub unsafe fn new(metadata_type: LLVMTypeRef) -> Self {
24 assert!(!metadata_type.is_null());
25
26 MetadataType {
27 metadata_type: Type::new(metadata_type),
28 }
29 }
30
31 #[llvm_versions(6..)]
43 pub fn fn_type(self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> {
44 self.metadata_type.fn_type(param_types, is_var_args)
45 }
46
47 #[llvm_versions(6..)]
60 pub fn get_context(self) -> ContextRef<'ctx> {
61 self.metadata_type.get_context()
62 }
63
64 pub fn print_to_string(self) -> LLVMString {
66 self.metadata_type.print_to_string()
67 }
68}
69
70unsafe impl AsTypeRef for MetadataType<'_> {
71 #[llvm_versions(6..)]
72 fn as_type_ref(&self) -> LLVMTypeRef {
73 self.metadata_type.ty
74 }
75
76 #[llvm_versions(..=5)]
77 fn as_type_ref(&self) -> LLVMTypeRef {
78 unimplemented!("MetadataType is only available in LLVM > 6.0")
79 }
80}
81
82impl Display for MetadataType<'_> {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84 write!(f, "{}", self.print_to_string())
85 }
86}