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 pub unsafe fn new(metadata_type: LLVMTypeRef) -> Self {
23 assert!(!metadata_type.is_null());
24
25 MetadataType {
26 metadata_type: Type::new(metadata_type),
27 }
28 }
29
30 pub fn fn_type(self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> {
42 self.metadata_type.fn_type(param_types, is_var_args)
43 }
44
45 pub fn get_context(self) -> ContextRef<'ctx> {
58 self.metadata_type.get_context()
59 }
60
61 pub fn print_to_string(self) -> LLVMString {
63 self.metadata_type.print_to_string()
64 }
65}
66
67unsafe impl AsTypeRef for MetadataType<'_> {
68 fn as_type_ref(&self) -> LLVMTypeRef {
69 self.metadata_type.ty
70 }
71}
72
73impl Display for MetadataType<'_> {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 write!(f, "{}", self.print_to_string())
76 }
77}