Extracted common macros to separate file
This commit is contained in:
parent
8aceddd48e
commit
cfa721f501
45
src/_common_macros.rs
Normal file
45
src/_common_macros.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -6,7 +6,12 @@ use crate::base_context::{
|
|||||||
use crate::directed_context::context::{
|
use crate::directed_context::context::{
|
||||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||||
};
|
};
|
||||||
use crate::relation_context::{BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext, DirectedBinaryTreeRelationSetterContext};
|
use crate::relation_context::{
|
||||||
|
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||||
|
DirectedBinaryTreeRelationSetterContext,
|
||||||
|
};
|
||||||
|
|
||||||
|
include!("../_common_macros.rs");
|
||||||
|
|
||||||
pub struct DynamicDirectedBinaryTreeContextFromContext<CtxRef> {
|
pub struct DynamicDirectedBinaryTreeContextFromContext<CtxRef> {
|
||||||
ctx: CtxRef,
|
ctx: CtxRef,
|
||||||
@ -37,31 +42,14 @@ impl<CtxRef> DynamicDirectedBinaryTreeContextFromContext<CtxRef> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx: NodeRefContainer> NodeRefContainer for DynamicDirectedBinaryTreeContextFromContext<&Ctx> {
|
_mut_switch!(_delegate_node_ref!(
|
||||||
type NodeRef = Ctx::NodeRef;
|
DynamicDirectedBinaryTreeContextFromContext
|
||||||
}
|
));
|
||||||
|
|
||||||
impl<Ctx: NodeRefContainer> NodeRefContainer
|
_mut_switch!(_delegate_parent_getter!(
|
||||||
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
|
DynamicDirectedBinaryTreeContextFromContext
|
||||||
{
|
));
|
||||||
type NodeRef = Ctx::NodeRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext
|
|
||||||
for DynamicDirectedBinaryTreeContextFromContext<&Ctx>
|
|
||||||
{
|
|
||||||
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
|
||||||
return self.ctx.getParent(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext
|
|
||||||
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
|
|
||||||
{
|
|
||||||
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
|
||||||
return self.ctx.getParent(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
||||||
for DynamicDirectedBinaryTreeContextFromContext<&Ctx>
|
for DynamicDirectedBinaryTreeContextFromContext<&Ctx>
|
||||||
|
|||||||
@ -11,12 +11,7 @@ use crate::relation_context::{
|
|||||||
DirectedBinaryTreeRelationSetterContext,
|
DirectedBinaryTreeRelationSetterContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! _mut_switch {
|
include!("../_common_macros.rs");
|
||||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
|
||||||
$macro$excl_mark($($args)+);
|
|
||||||
$macro$excl_mark($($args)+ mut);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FixedLeftDirectedBinaryTreeContextFromContext<CtxRef> {
|
pub struct FixedLeftDirectedBinaryTreeContextFromContext<CtxRef> {
|
||||||
ctx: CtxRef,
|
ctx: CtxRef,
|
||||||
@ -26,52 +21,14 @@ pub struct FixedRightDirectedBinaryTreeContextFromContext<CtxRef> {
|
|||||||
ctx: CtxRef,
|
ctx: CtxRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! _constructor {
|
_mut_switch!(_ctx_wrapper_constructor!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||||
($name:ident) => {
|
_mut_switch!(_ctx_wrapper_constructor!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||||
impl<'ctx, Ctx: NodeRefContainer> $name<&'ctx Ctx> {
|
|
||||||
pub fn wrap(ctx: &'ctx Ctx) -> Self {
|
|
||||||
return Self { ctx };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
($name:ident mut) => {
|
_mut_switch!(_delegate_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||||
impl<'ctx, Ctx: NodeRefContainer> $name<&'ctx mut Ctx> {
|
_mut_switch!(_delegate_node_ref!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||||
pub fn wrap_mut(ctx: &'ctx mut Ctx) -> Self {
|
|
||||||
return Self { ctx };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_mut_switch!(_constructor!(FixedLeftDirectedBinaryTreeContextFromContext));
|
_mut_switch!(_delegate_parent_getter!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||||
_mut_switch!(_constructor!(FixedRightDirectedBinaryTreeContextFromContext));
|
_mut_switch!(_delegate_parent_getter!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||||
|
|
||||||
macro_rules! _node_ref {
|
|
||||||
($name:ident $($mut:tt)?) => {
|
|
||||||
impl<Ctx: NodeRefContainer> NodeRefContainer for $name<& $($mut)? Ctx> {
|
|
||||||
type NodeRef = Ctx::NodeRef;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_mut_switch!(_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext));
|
|
||||||
_mut_switch!(_node_ref!(FixedRightDirectedBinaryTreeContextFromContext));
|
|
||||||
|
|
||||||
macro_rules! _parent_get {
|
|
||||||
($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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_mut_switch!(_parent_get!(FixedLeftDirectedBinaryTreeContextFromContext));
|
|
||||||
_mut_switch!(_parent_get!(FixedRightDirectedBinaryTreeContextFromContext));
|
|
||||||
|
|
||||||
macro_rules! _children_get {
|
macro_rules! _children_get {
|
||||||
($name:ident $fwd:ident $op:ident $($mut:tt)? ) => {
|
($name:ident $fwd:ident $op:ident $($mut:tt)? ) => {
|
||||||
|
|||||||
@ -16,12 +16,7 @@ use crate::relation_context::{
|
|||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
macro_rules! _mut_switch {
|
include!("../_common_macros.rs");
|
||||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
|
||||||
$macro$excl_mark($($args)+);
|
|
||||||
$macro$excl_mark($($args)+ mut);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
union _NodeOrNothing<NodeRef> {
|
union _NodeOrNothing<NodeRef> {
|
||||||
nothing: (),
|
nothing: (),
|
||||||
|
|||||||
@ -11,12 +11,7 @@ use crate::parent2node_clojure::clojure::{
|
|||||||
};
|
};
|
||||||
use crate::relation_context::{BinaryTreeRootRelationSetterContext, Parent2NodeRelationSetterClojure};
|
use crate::relation_context::{BinaryTreeRootRelationSetterContext, Parent2NodeRelationSetterClojure};
|
||||||
|
|
||||||
macro_rules! _mut_switch {
|
include!("../_common_macros.rs");
|
||||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
|
||||||
$macro$excl_mark($($args)+);
|
|
||||||
$macro$excl_mark($($args)+ mut);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! _struct {
|
macro_rules! _struct {
|
||||||
($name:ident) => {
|
($name:ident) => {
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
use crate::NodeRefContainer;
|
use crate::NodeRefContainer;
|
||||||
use crate::base_context::{BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootSetter};
|
use crate::base_context::{
|
||||||
use crate::directed_context::{DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext};
|
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
||||||
|
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootSetter,
|
||||||
|
};
|
||||||
|
use crate::directed_context::{
|
||||||
|
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||||
|
};
|
||||||
use crate::relation_context::{
|
use crate::relation_context::{
|
||||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||||
DirectedBinaryTreeRelationSetterContext,
|
DirectedBinaryTreeRelationSetterContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! _mut_switch {
|
include!("../_common_macros.rs");
|
||||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
|
||||||
$macro$excl_mark($($args)+);
|
|
||||||
$macro$excl_mark($($args)+ mut);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BinaryTreeRelationContextFromBaseContextConverter<CtxRef> {
|
pub struct BinaryTreeRelationContextFromBaseContextConverter<CtxRef> {
|
||||||
ctx: CtxRef,
|
ctx: CtxRef,
|
||||||
@ -21,62 +21,25 @@ pub struct DirectedBinaryTreeRelationContextFromBaseContextConverter<CtxRef> {
|
|||||||
ctx: CtxRef,
|
ctx: CtxRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! _constructor {
|
_mut_switch!(_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 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_mut_switch!(_constructor!(
|
|
||||||
BinaryTreeRelationContextFromBaseContextConverter
|
BinaryTreeRelationContextFromBaseContextConverter
|
||||||
));
|
));
|
||||||
_mut_switch!(_constructor!(
|
_mut_switch!(_ctx_wrapper_constructor!(
|
||||||
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
||||||
));
|
));
|
||||||
|
|
||||||
macro_rules! _node_ref {
|
_mut_switch!(_delegate_node_ref!(
|
||||||
($name:ident $($mut:tt)?) => {
|
|
||||||
impl<Ctx: NodeRefContainer> NodeRefContainer for $name<& $($mut)? Ctx> {
|
|
||||||
type NodeRef = Ctx::NodeRef;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_mut_switch!(_node_ref!(
|
|
||||||
BinaryTreeRelationContextFromBaseContextConverter
|
BinaryTreeRelationContextFromBaseContextConverter
|
||||||
));
|
));
|
||||||
_mut_switch!(_node_ref!(
|
_mut_switch!(_delegate_node_ref!(
|
||||||
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
||||||
));
|
));
|
||||||
|
|
||||||
macro_rules! _parent_get {
|
|
||||||
($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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_mut_switch!(_parent_get!(
|
_mut_switch!(_delegate_parent_getter!(
|
||||||
BinaryTreeRelationContextFromBaseContextConverter
|
BinaryTreeRelationContextFromBaseContextConverter
|
||||||
));
|
));
|
||||||
_mut_switch!(_parent_get!(
|
_mut_switch!(_delegate_parent_getter!(
|
||||||
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user