1use mlir_sys::MlirLogicalResult;
2
3#[derive(Clone, Copy, Debug)]
5pub struct LogicalResult {
6 raw: MlirLogicalResult,
7}
8
9impl LogicalResult {
10 pub const fn success() -> Self {
12 Self {
13 raw: MlirLogicalResult { value: 1 },
14 }
15 }
16
17 pub const fn failure() -> Self {
19 Self {
20 raw: MlirLogicalResult { value: 0 },
21 }
22 }
23
24 pub const fn is_success(&self) -> bool {
26 self.raw.value != 0
27 }
28
29 #[allow(dead_code)]
31 pub const fn is_failure(&self) -> bool {
32 self.raw.value == 0
33 }
34
35 pub const fn from_raw(result: MlirLogicalResult) -> Self {
37 Self { raw: result }
38 }
39
40 pub const fn to_raw(self) -> MlirLogicalResult {
42 self.raw
43 }
44}
45
46impl From<bool> for LogicalResult {
47 fn from(ok: bool) -> Self {
48 if ok {
49 Self::success()
50 } else {
51 Self::failure()
52 }
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn success() {
62 assert!(LogicalResult::success().is_success());
63 }
64
65 #[test]
66 fn failure() {
67 assert!(LogicalResult::failure().is_failure());
68 }
69}