pub trait Closable<State> {
type ClosedSet<T>: ClosedSet<State, T>;
fn new_closed_set<T>(&self) -> Self::ClosedSet<T>;
}
#[must_use]
pub enum CloseResult<'a, T> {
Accepted,
Rejected {
value: T,
prior: &'a mut T,
},
}
impl<'a, T> CloseResult<'a, T> {
pub fn accepted(&self) -> bool {
match self {
Self::Accepted => true,
Self::Rejected { .. } => false,
}
}
pub fn rejected(&self) -> bool {
!self.accepted()
}
}
#[must_use]
pub enum ClosedStatus<'a, T> {
Open,
Closed(&'a T),
}
impl<'a, T> ClosedStatus<'a, T> {
pub fn is_open(&self) -> bool {
match self {
Self::Open => true,
Self::Closed(_) => false,
}
}
pub fn is_closed(&self) -> bool {
!self.is_open()
}
pub fn closed(self) -> Option<&'a T> {
match self {
Self::Open => None,
Self::Closed(t) => Some(t),
}
}
}
impl<'a, T> From<Option<&'a T>> for ClosedStatus<'a, T> {
fn from(value: Option<&'a T>) -> Self {
match value {
Some(v) => ClosedStatus::Closed(v),
None => ClosedStatus::Open,
}
}
}
pub trait ClosedSet<State, T> {
fn close<'a>(&'a mut self, state: &State, value: T) -> CloseResult<'a, T>;
fn replace(&mut self, state: &State, value: T) -> Option<T>;
fn status<'a>(&'a self, state: &State) -> ClosedStatus<'a, T>;
}
pub trait ClosedStatusForKey<Key, T> {
fn status_for_key<'a>(&'a self, key: &Key) -> ClosedStatus<'a, T>;
fn closed_keys_len(&self) -> usize;
}
pub trait AsTimeVariant {
type TimeVariantClosable;
fn as_time_variant(self) -> Self::TimeVariantClosable;
}
pub trait AsTimeInvariant {
type TimeInvariantClosable;
fn as_time_invariant(self) -> Self::TimeInvariantClosable;
}
pub mod keyed_closed_set;
pub use keyed_closed_set::*;
pub mod partial_keyed_closed_set;
pub use partial_keyed_closed_set::*;
pub mod time_variant_keyed_closed_set;
pub use time_variant_keyed_closed_set::*;
pub mod time_variant_partial_keyed_closed_set;
pub use time_variant_partial_keyed_closed_set::*;