#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum TsCommandType {
NotDefined,
CreateTablespace,
AlterTablespace,
CreateLogfileGroup,
AlterLogfileGroup,
DropTablespace,
DropLogfileGroup,
ChangeFileTablespace,
AlterAccessModeTablespace,
CreateUndoTablespace,
AlterUndoTablespace,
DropUndoTablespace,
Unknown,
}
impl TsCommandType {
#[must_use]
pub const fn from_raw(value: i32) -> Self {
match value {
-1 => Self::NotDefined,
0 => Self::CreateTablespace,
1 => Self::AlterTablespace,
2 => Self::CreateLogfileGroup,
3 => Self::AlterLogfileGroup,
4 => Self::DropTablespace,
5 => Self::DropLogfileGroup,
6 => Self::ChangeFileTablespace,
7 => Self::AlterAccessModeTablespace,
8 => Self::CreateUndoTablespace,
9 => Self::AlterUndoTablespace,
10 => Self::DropUndoTablespace,
_ => Self::Unknown,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum TablespaceType {
Dictionary,
System,
Undo,
Temporary,
Shared,
Implicit,
}
impl TablespaceType {
#[must_use]
pub const fn to_raw(self) -> u32 {
match self {
Self::Dictionary => 0,
Self::System => 1,
Self::Undo => 2,
Self::Temporary => 3,
Self::Shared => 4,
Self::Implicit => 5,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ts_command_known_values() {
assert_eq!(TsCommandType::from_raw(-1), TsCommandType::NotDefined);
assert_eq!(TsCommandType::from_raw(0), TsCommandType::CreateTablespace);
assert_eq!(
TsCommandType::from_raw(10),
TsCommandType::DropUndoTablespace
);
}
#[test]
fn ts_command_unknown_falls_back() {
assert_eq!(TsCommandType::from_raw(99), TsCommandType::Unknown);
assert_eq!(TsCommandType::from_raw(-99), TsCommandType::Unknown);
}
#[test]
fn tablespace_type_to_raw_round_trip() {
let pairs = [
(TablespaceType::Dictionary, 0),
(TablespaceType::System, 1),
(TablespaceType::Undo, 2),
(TablespaceType::Temporary, 3),
(TablespaceType::Shared, 4),
(TablespaceType::Implicit, 5),
];
for (v, raw) in pairs {
assert_eq!(v.to_raw(), raw);
}
}
}