use mlir_sys::MlirLogicalResult;
#[derive(Clone, Copy, Debug)]
pub struct LogicalResult {
raw: MlirLogicalResult,
}
impl LogicalResult {
pub const fn success() -> Self {
Self {
raw: MlirLogicalResult { value: 1 },
}
}
pub const fn failure() -> Self {
Self {
raw: MlirLogicalResult { value: 0 },
}
}
pub const fn is_success(&self) -> bool {
self.raw.value != 0
}
#[allow(dead_code)]
pub const fn is_failure(&self) -> bool {
self.raw.value == 0
}
pub const fn from_raw(result: MlirLogicalResult) -> Self {
Self { raw: result }
}
pub const fn to_raw(self) -> MlirLogicalResult {
self.raw
}
}
impl From<bool> for LogicalResult {
fn from(ok: bool) -> Self {
if ok {
Self::success()
} else {
Self::failure()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn success() {
assert!(LogicalResult::success().is_success());
}
#[test]
fn failure() {
assert!(LogicalResult::failure().is_failure());
}
}