feat(Direction): add Direction::perpendicular(self) (#2197)
This commit is contained in:
@@ -12,11 +12,27 @@ use strum::{Display, EnumString};
|
||||
#[derive(Debug, Default, Display, EnumString, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Direction {
|
||||
/// Layout segments are arranged side by side (left to right).
|
||||
Horizontal,
|
||||
/// Layout segments are arranged top to bottom (default).
|
||||
#[default]
|
||||
Vertical,
|
||||
}
|
||||
|
||||
impl Direction {
|
||||
/// The perpendicular direction to this direction.
|
||||
///
|
||||
/// `Horizontal` returns `Vertical`, and `Vertical` returns `Horizontal`.
|
||||
#[inline]
|
||||
#[must_use = "returns the perpendicular direction"]
|
||||
pub const fn perpendicular(self) -> Self {
|
||||
match self {
|
||||
Self::Horizontal => Self::Vertical,
|
||||
Self::Vertical => Self::Horizontal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloc::string::ToString;
|
||||
@@ -37,4 +53,11 @@ mod tests {
|
||||
assert_eq!("Vertical".parse::<Direction>(), Ok(Direction::Vertical));
|
||||
assert_eq!("".parse::<Direction>(), Err(ParseError::VariantNotFound));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other() {
|
||||
use Direction::*;
|
||||
assert_eq!(Horizontal.perpendicular(), Vertical);
|
||||
assert_eq!(Vertical.perpendicular(), Horizontal);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user