#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Scope {
#[default]
Default,
All,
Workspace,
}
impl Scope {
#[must_use]
pub fn from_flags(all: bool, workspace: bool) -> Option<Self> {
match (all, workspace) {
(false, false) => Some(Self::Default),
(true, false) => Some(Self::All),
(false, true) => Some(Self::Workspace),
(true, true) => None,
}
}
}
#[cfg(test)]
mod tests {
use super::Scope;
#[test]
fn default_is_the_no_flag_variant() {
assert_eq!(Scope::default(), Scope::Default);
}
#[test]
fn from_flags_maps_neither_to_default() {
assert_eq!(Scope::from_flags(false, false), Some(Scope::Default));
}
#[test]
fn from_flags_maps_all_only_to_all() {
assert_eq!(Scope::from_flags(true, false), Some(Scope::All));
}
#[test]
fn from_flags_maps_workspace_only_to_workspace() {
assert_eq!(Scope::from_flags(false, true), Some(Scope::Workspace));
}
#[test]
fn from_flags_rejects_both_set() {
assert_eq!(Scope::from_flags(true, true), None);
}
}