use core::fmt;
use core::ops::BitOr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Direction {
Forward,
Backward,
}
impl Direction {
#[must_use]
pub const fn sign(self) -> i32 {
match self {
Self::Forward => -1,
Self::Backward => 1,
}
}
}
impl TryFrom<i32> for Direction {
type Error = InvalidDirection;
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
-1 => Ok(Self::Forward),
1 => Ok(Self::Backward),
n => Err(InvalidDirection(n)),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InvalidDirection(pub i32);
impl fmt::Display for InvalidDirection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"invalid direction value {}: expected -1 (forward) or 1 (backward)",
self.0
)
}
}
impl core::error::Error for InvalidDirection {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Flags(u32);
impl Flags {
pub const ESTIMATE: Self = Self(0);
pub const MEASURE: Self = Self(1 << 0);
pub const PATIENT: Self = Self(1 << 1);
pub const EXHAUSTIVE: Self = Self(1 << 2);
pub const PRESERVE_INPUT: Self = Self(1 << 3);
pub const DESTROY_INPUT: Self = Self(1 << 4);
pub const UNALIGNED: Self = Self(1 << 5);
#[must_use]
pub const fn is_measure(self) -> bool {
self.0 & Self::MEASURE.0 != 0
}
#[must_use]
pub const fn is_patient(self) -> bool {
self.0 & Self::PATIENT.0 != 0
}
#[must_use]
pub const fn is_exhaustive(self) -> bool {
self.0 & Self::EXHAUSTIVE.0 != 0
}
#[must_use]
pub const fn can_destroy_input(self) -> bool {
self.0 & Self::DESTROY_INPUT.0 != 0
}
}
impl BitOr for Flags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum R2rKind {
DctI,
DctII,
DctIII,
DctIV,
DstI,
DstII,
DstIII,
DstIV,
Dht,
Hc2r,
R2hc,
}