#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BinlogFunc {
ResetLogs,
ResetSlave,
BinlogWait,
BinlogEnd,
BinlogPurgeFile,
BinlogPurgeWait,
Unknown,
}
impl BinlogFunc {
#[must_use]
pub const fn from_raw(value: u32) -> Self {
match value {
1 => Self::ResetLogs,
2 => Self::ResetSlave,
3 => Self::BinlogWait,
4 => Self::BinlogEnd,
5 => Self::BinlogPurgeFile,
6 => Self::BinlogPurgeWait,
_ => Self::Unknown,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BinlogCommand {
CreateTable,
AlterTable,
RenameTable,
DropTable,
CreateDb,
AlterDb,
DropDb,
Unknown,
}
impl BinlogCommand {
#[must_use]
pub const fn from_raw(value: u32) -> Self {
match value {
0 => Self::CreateTable,
1 => Self::AlterTable,
2 => Self::RenameTable,
3 => Self::DropTable,
4 => Self::CreateDb,
5 => Self::AlterDb,
6 => Self::DropDb,
_ => Self::Unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn binlog_func_known_values() {
assert_eq!(BinlogFunc::from_raw(1), BinlogFunc::ResetLogs);
assert_eq!(BinlogFunc::from_raw(6), BinlogFunc::BinlogPurgeWait);
}
#[test]
fn binlog_func_unknown_falls_back() {
assert_eq!(BinlogFunc::from_raw(0), BinlogFunc::Unknown);
assert_eq!(BinlogFunc::from_raw(99), BinlogFunc::Unknown);
}
#[test]
fn binlog_command_known_values() {
assert_eq!(BinlogCommand::from_raw(0), BinlogCommand::CreateTable);
assert_eq!(BinlogCommand::from_raw(6), BinlogCommand::DropDb);
}
#[test]
fn binlog_command_unknown_falls_back() {
assert_eq!(BinlogCommand::from_raw(99), BinlogCommand::Unknown);
}
}