use arbitrary::Arbitrary;
use mkit::Cborize;
use std::{
cmp,
fmt::{self, Display},
result,
};
#[derive(Debug, Clone, Default, Cborize, Arbitrary)]
pub struct Entry {
seqno: u64,
op: Vec<u8>,
}
impl Eq for Entry {}
impl PartialEq for Entry {
fn eq(&self, other: &Self) -> bool {
self.seqno.eq(&other.seqno)
}
}
impl Display for Entry {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
write!(f, "entry<seqno:{}>", self.seqno)
}
}
impl PartialOrd for Entry {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Entry {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.seqno.cmp(&other.seqno)
}
}
impl Entry {
const ID: u32 = 0x0;
#[inline]
pub fn new(seqno: u64, op: Vec<u8>) -> Entry {
Entry { seqno, op }
}
#[inline]
pub fn to_seqno(&self) -> u64 {
self.seqno
}
#[inline]
pub fn unwrap(self) -> (u64, Vec<u8>) {
(self.seqno, self.op)
}
}
#[cfg(test)]
#[path = "entry_test.rs"]
mod entry_test;