binary-tree-core-0.rs/src/_common_macros.rs

46 lines
1.2 KiB
Rust

macro_rules! _mut_switch {
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
$macro$excl_mark($($args)+);
$macro$excl_mark($($args)+ mut);
};
}
macro_rules! _ctx_wrapper_constructor {
($name:ident) => {
impl<'ctx, Ctx: NodeRefContainer> $name<&'ctx Ctx> {
pub fn wrap(ctx: &'ctx Ctx) -> Self {
return Self { ctx };
}
}
};
($name:ident mut) => {
impl<'ctx, Ctx: NodeRefContainer> $name<&'ctx mut Ctx> {
pub fn wrap_mut(ctx: &'ctx mut Ctx) -> Self {
return Self { ctx };
}
}
};
}
macro_rules! _delegate_node_ref {
($name:ident $($mut:tt)?) => {
impl<Ctx: NodeRefContainer> NodeRefContainer for $name<& $($mut)? Ctx> {
type NodeRef = Ctx::NodeRef;
}
};
}
macro_rules! _delegate_parent_getter {
($name:ident $($mut:tt)?) => {
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext
for $name<& $($mut)? Ctx>
{
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
return self.ctx.getParent(node);
}
}
};
}