melior/ir/attribute/
macro.rs1macro_rules! attribute_traits {
2 ($name: ident, $is_type: ident, $string: expr) => {
3 impl<'c> $name<'c> {
4 unsafe fn from_raw(raw: MlirAttribute) -> Self {
5 Self {
6 attribute: Attribute::from_raw(raw),
7 }
8 }
9 }
10
11 impl<'c> TryFrom<crate::ir::attribute::Attribute<'c>> for $name<'c> {
12 type Error = crate::Error;
13
14 fn try_from(
15 attribute: crate::ir::attribute::Attribute<'c>,
16 ) -> Result<Self, Self::Error> {
17 if attribute.$is_type() {
18 Ok(unsafe { Self::from_raw(attribute.to_raw()) })
19 } else {
20 Err(Error::AttributeExpected($string, attribute.to_string()))
21 }
22 }
23 }
24
25 impl<'c> crate::ir::attribute::AttributeLike<'c> for $name<'c> {
26 fn to_raw(&self) -> mlir_sys::MlirAttribute {
27 self.attribute.to_raw()
28 }
29 }
30
31 impl<'c> std::fmt::Display for $name<'c> {
32 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
33 std::fmt::Display::fmt(&self.attribute, formatter)
34 }
35 }
36
37 impl<'c> std::fmt::Debug for $name<'c> {
38 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
39 std::fmt::Display::fmt(self, formatter)
40 }
41 }
42 };
43}