1macro_rules! type_traits {
2 ($name: ident, $is_type: ident, $string: expr) => {
3 impl<'c> $name<'c> {
4 unsafe fn from_raw(raw: MlirType) -> Self {
5 Self {
6 r#type: Type::from_raw(raw),
7 }
8 }
9 }
10
11 impl<'c> TryFrom<crate::ir::r#type::Type<'c>> for $name<'c> {
12 type Error = crate::Error;
13
14 fn try_from(r#type: crate::ir::r#type::Type<'c>) -> Result<Self, Self::Error> {
15 if r#type.$is_type() {
16 Ok(unsafe { Self::from_raw(r#type.to_raw()) })
17 } else {
18 Err(Error::TypeExpected($string, r#type.to_string()))
19 }
20 }
21 }
22
23 impl<'c> crate::ir::r#type::TypeLike<'c> for $name<'c> {
24 fn to_raw(&self) -> mlir_sys::MlirType {
25 self.r#type.to_raw()
26 }
27 }
28
29 impl<'c> std::fmt::Display for $name<'c> {
30 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
31 std::fmt::Display::fmt(&self.r#type, formatter)
32 }
33 }
34 };
35}