use super::ser::SerializerState;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Direction {
LeftFirst,
#[allow(dead_code)]
RightFirst,
}
impl Direction {
pub(super) fn cons_opcode(self) -> i64 {
match self {
Direction::LeftFirst => 1,
Direction::RightFirst => -1,
}
}
}
pub trait VisitStrategy {
type NodeCtx: Copy;
fn root_ctx(&self, state: &SerializerState) -> Self::NodeCtx;
fn decide(
&self,
state: &SerializerState,
pair_idx: usize,
ctx: Self::NodeCtx,
) -> (Direction, Self::NodeCtx, Self::NodeCtx);
}
pub struct LeftFirst;
impl VisitStrategy for LeftFirst {
type NodeCtx = ();
fn root_ctx(&self, _state: &SerializerState) -> Self::NodeCtx {}
fn decide(&self, _state: &SerializerState, _pair_idx: usize, _ctx: ()) -> (Direction, (), ()) {
(Direction::LeftFirst, (), ())
}
}