#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct StorageCapabilities {
pub atomic: bool,
pub change_capture: bool,
pub isolation: IsolationLevel,
pub concurrent_writers: bool,
pub durability: bool,
pub writable: bool,
pub immutable: bool,
}
impl StorageCapabilities {
pub const fn none() -> Self {
Self {
atomic: false,
change_capture: false,
isolation: IsolationLevel::None,
concurrent_writers: false,
durability: false,
writable: false,
immutable: false,
}
}
pub const fn with_atomic(mut self, atomic: bool) -> Self {
self.atomic = atomic;
self
}
pub const fn with_change_capture(mut self, change_capture: bool) -> Self {
self.change_capture = change_capture;
self
}
pub const fn with_isolation(mut self, isolation: IsolationLevel) -> Self {
self.isolation = isolation;
self
}
pub const fn with_concurrent_writers(mut self, concurrent_writers: bool) -> Self {
self.concurrent_writers = concurrent_writers;
self
}
pub const fn with_durability(mut self, durability: bool) -> Self {
self.durability = durability;
self
}
pub const fn with_writable(mut self, writable: bool) -> Self {
self.writable = writable;
self
}
pub const fn with_immutable(mut self, immutable: bool) -> Self {
self.immutable = immutable;
self
}
pub const fn is_consistent(&self) -> bool {
(!self.change_capture || self.atomic) && !(self.writable && self.immutable)
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum IsolationLevel {
#[default]
None,
Snapshot,
}