1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
use std::{ default::Default, fmt::{self, Display, Formatter}, ops::{Add, AddAssign}, }; #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub enum Op { Read, Write, Add, NoOp, } impl Add for Op { type Output = Op; fn add(self, other: Op) -> Op { match (self, other) { (a, Op::NoOp) => a, (Op::NoOp, b) => b, (Op::Read, Op::Read) => Op::Read, (Op::Add, Op::Add) => Op::Add, _ => Op::Write, } } } impl AddAssign for Op { fn add_assign(&mut self, other: Self) { *self = *self + other; } } impl Display for Op { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "{:?}", self) } } impl Default for Op { fn default() -> Self { Op::NoOp } } impl From<&Op> for casper_types::OpKind { fn from(op: &Op) -> Self { match op { Op::Read => casper_types::OpKind::Read, Op::Write => casper_types::OpKind::Write, Op::Add => casper_types::OpKind::Add, Op::NoOp => casper_types::OpKind::NoOp, } } }