#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Readiness {
pub author_ready: bool,
pub maintainer_ready: bool,
pub read_only: bool,
}
impl Readiness {
#[must_use]
pub const fn none() -> Self {
Self {
author_ready: false,
maintainer_ready: false,
read_only: false,
}
}
#[must_use]
pub const fn may_operate(self) -> bool {
!self.read_only
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Capability {
Viewer,
Author,
Maintainer,
}
impl Capability {
#[must_use]
pub const fn derive(readiness: Readiness) -> Self {
if readiness.read_only {
return Self::Viewer;
}
if readiness.maintainer_ready {
Self::Maintainer
} else if readiness.author_ready {
Self::Author
} else {
Self::Viewer
}
}
#[must_use]
pub const fn may_author(self) -> bool {
matches!(self, Self::Author | Self::Maintainer)
}
#[must_use]
pub const fn may_publish(self) -> bool {
matches!(self, Self::Maintainer)
}
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Viewer => "viewer",
Self::Author => "author",
Self::Maintainer => "maintainer",
}
}
}
#[cfg(test)]
mod tests;