#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Direction {
Input,
Output,
}
impl Direction {
pub fn as_raw(&self) -> spa_sys::spa_direction {
match self {
Self::Input => spa_sys::spa_direction_SPA_DIRECTION_INPUT,
Self::Output => spa_sys::spa_direction_SPA_DIRECTION_OUTPUT,
}
}
pub fn from_raw(raw: spa_sys::spa_direction) -> Self {
match raw {
spa_sys::spa_direction_SPA_DIRECTION_INPUT => Self::Input,
spa_sys::spa_direction_SPA_DIRECTION_OUTPUT => Self::Output,
_ => panic!("Invalid direction: {}", raw),
}
}
pub fn reverse(&self) -> Self {
match self {
Self::Input => Self::Output,
Self::Output => Self::Input,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn as_raw() {
assert_eq!(
Direction::Input.as_raw(),
spa_sys::spa_direction_SPA_DIRECTION_INPUT
);
assert_eq!(
Direction::Output.as_raw(),
spa_sys::spa_direction_SPA_DIRECTION_OUTPUT
);
}
#[test]
fn from_raw() {
assert_eq!(
Direction::Input,
Direction::from_raw(spa_sys::spa_direction_SPA_DIRECTION_INPUT)
);
assert_eq!(
Direction::Output,
Direction::from_raw(spa_sys::spa_direction_SPA_DIRECTION_OUTPUT)
);
}
#[test]
#[should_panic]
fn invalid_direction() {
Direction::from_raw(u32::MAX);
}
#[test]
fn reverse() {
assert_eq!(Direction::Output.reverse(), Direction::Input);
assert_eq!(Direction::Input.reverse(), Direction::Output);
}
}