1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::{Attribute, AttributeLike};
use crate::{Context, Error};
use mlir_sys::{mlirBoolAttrGet, mlirBoolAttrGetValue, MlirAttribute};

/// A bool attribute.
#[derive(Clone, Copy)]
pub struct BoolAttribute<'c> {
    attribute: Attribute<'c>,
}

impl<'c> BoolAttribute<'c> {
    /// Creates a bool attribute.
    pub fn new(context: &'c Context, boolean: bool) -> Self {
        unsafe {
            Self::from_raw(mlirBoolAttrGet(
                context.to_raw(),
                if boolean { 1 } else { 0 },
            ))
        }
    }

    /// Returns a value.
    pub fn value(&self) -> bool {
        unsafe { mlirBoolAttrGetValue(self.to_raw()) }
    }
}

attribute_traits!(BoolAttribute, is_string, "string");

#[cfg(test)]
mod tests {
    use super::*;
    use crate::test::create_test_context;

    #[test]
    fn value() {
        let context = create_test_context();
        let value = BoolAttribute::new(&context, true).value();

        assert!(value);
    }
}