use std::fmt;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IsolationLevel {
Shared,
#[default]
StreamIsolated,
ContextIsolated,
}
impl IsolationLevel {
pub fn name(&self) -> &'static str {
match self {
IsolationLevel::Shared => "shared",
IsolationLevel::StreamIsolated => "stream_isolated",
IsolationLevel::ContextIsolated => "context_isolated",
}
}
}
impl fmt::Display for IsolationLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_is_stream_isolated() {
assert_eq!(IsolationLevel::default(), IsolationLevel::StreamIsolated);
}
#[test]
fn names_are_stable() {
assert_eq!(IsolationLevel::Shared.name(), "shared");
assert_eq!(IsolationLevel::StreamIsolated.name(), "stream_isolated");
assert_eq!(IsolationLevel::ContextIsolated.name(), "context_isolated");
}
#[test]
fn display_matches_name() {
assert_eq!(IsolationLevel::Shared.to_string(), "shared");
assert_eq!(
IsolationLevel::ContextIsolated.to_string(),
"context_isolated"
);
}
#[test]
fn levels_are_ord_independent_but_distinct() {
assert_ne!(IsolationLevel::Shared, IsolationLevel::StreamIsolated);
assert_ne!(
IsolationLevel::StreamIsolated,
IsolationLevel::ContextIsolated
);
}
}