#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WriteGate(bool);
impl WriteGate {
pub const VARIABLE: &'static str = "WEAVATRIX_ALLOW_SOURCE_EDITS";
#[must_use]
pub fn from_environment() -> Self {
Self(std::env::var(Self::VARIABLE).is_ok_and(|value| value == "1"))
}
#[cfg(test)]
#[must_use]
pub const fn closed() -> Self {
Self(false)
}
#[cfg(test)]
#[must_use]
pub const fn open() -> Self {
Self(true)
}
#[must_use]
pub const fn is_open(self) -> bool {
self.0
}
}
#[cfg(test)]
mod tests {
use super::WriteGate;
#[test]
fn a_closed_gate_never_reports_open() {
assert!(!WriteGate::closed().is_open());
}
#[test]
fn the_variable_name_is_the_documented_one() {
assert_eq!(WriteGate::VARIABLE, "WEAVATRIX_ALLOW_SOURCE_EDITS");
}
}