diff --git a/src/directed/dynamic_wrapper.rs b/src/directed/dynamic_wrapper.rs index 1dd7ee6..b73ff17 100644 --- a/src/directed/dynamic_wrapper.rs +++ b/src/directed/dynamic_wrapper.rs @@ -20,7 +20,7 @@ impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeContextFromContext<&' } impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeContextFromContext<&'ctx mut Ctx> { - pub fn wrap(ctx: &'ctx mut Ctx, initialDirection: BinaryTreeDirection) -> Self { + pub fn wrap_mut(ctx: &'ctx mut Ctx, initialDirection: BinaryTreeDirection) -> Self { return Self { ctx, dir: initialDirection, diff --git a/src/directed/fixed_wrapper.rs b/src/directed/fixed_wrapper.rs index 6f2f377..603b9e5 100644 --- a/src/directed/fixed_wrapper.rs +++ b/src/directed/fixed_wrapper.rs @@ -23,9 +23,17 @@ pub struct FixedRightDirectedBinaryTreeContextFromContext { } macro_rules! _constructor { - ($name:ident $($mut:tt)?) => { - impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx> { - pub fn wrap(ctx: &'ctx $($mut)? Ctx) -> Self { + ($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 }; } } diff --git a/src/parent2node/dynamic_wrappers.rs b/src/parent2node/dynamic_wrappers.rs index 0dc62ae..f9537f1 100644 --- a/src/parent2node/dynamic_wrappers.rs +++ b/src/parent2node/dynamic_wrappers.rs @@ -37,10 +37,10 @@ struct DynamicParent2NodeGetterClojureFromDirectedContext { } macro_rules! _constructor { - ($name:ident $direction:ident $($mut:tt)?) => { - impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx, Ctx::NodeRef> { - pub fn wrap_not_root( - ctx: &'ctx $($mut)? Ctx, node: Ctx::NodeRef, direction: $direction + ($name:ident $direction:ident) => { + impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx Ctx, Ctx::NodeRef> { + pub fn wrapNode( + ctx: &'ctx Ctx, node: Ctx::NodeRef, direction: $direction ) -> Self { return Self { dir: Some(direction), @@ -48,6 +48,39 @@ macro_rules! _constructor { node: _NodeOrNothing { node: ManuallyDrop::new(node) } }; } + + pub fn wrapRoot( + ctx: &'ctx Ctx + ) -> Self { + return Self { + dir: None, + ctx: ctx, + node: _NodeOrNothing { nothing: () } + }; + } + } + }; + ($name:ident $direction:ident mut) => { + impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx mut Ctx, Ctx::NodeRef> { + pub fn wrapNode_mut( + ctx: &'ctx mut Ctx, node: Ctx::NodeRef, direction: $direction + ) -> Self { + return Self { + dir: Some(direction), + ctx: ctx, + node: _NodeOrNothing { node: ManuallyDrop::new(node) } + }; + } + + pub fn wrapRoot_mut( + ctx: &'ctx mut Ctx + ) -> Self { + return Self { + dir: None, + ctx: ctx, + node: _NodeOrNothing { nothing: () } + }; + } } }; } diff --git a/src/parent2node/fixed_wrapper.rs b/src/parent2node/fixed_wrapper.rs index 7accacc..214c7fd 100644 --- a/src/parent2node/fixed_wrapper.rs +++ b/src/parent2node/fixed_wrapper.rs @@ -19,14 +19,14 @@ macro_rules! _mut_switch { macro_rules! _struct { ($name:ident) => { - struct $name { + pub struct $name { ctx: CtxRef, node: NodeRef, } }; } -struct FixedRootParent2NodeGetterClojureFromContext { +pub struct FixedRootParent2NodeGetterClojureFromContext { ctx: NodeRef, } _struct!(FixedLeftParent2NodeGetterClojureFromContext); @@ -35,9 +35,17 @@ _struct!(FixedForwardParent2NodeGetterClojureFromDirectedContext); _struct!(FixedOppositeParent2NodeGetterClojureFromDirectedContext); macro_rules! _constructor { - ($name:ident $($mut:tt)?) => { - impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx, Ctx::NodeRef> { - pub fn wrap(ctx: &'ctx $($mut)? Ctx, node: Ctx::NodeRef) -> Self { + ($name:ident) => { + impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx Ctx, Ctx::NodeRef> { + pub fn wrap(ctx: &'ctx Ctx, node: Ctx::NodeRef) -> Self { + return Self { ctx, node }; + } + } + }; + + ($name:ident mut) => { + impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx mut Ctx, Ctx::NodeRef> { + pub fn wrap_mut(ctx: &'ctx mut Ctx, node: Ctx::NodeRef) -> Self { return Self { ctx, node }; } } @@ -53,7 +61,7 @@ impl<'ctx, Ctx: NodeRefContainer + BinaryTreeRootGetter> } impl<'ctx, Ctx: NodeRefContainer> FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx> { - fn wrap(ctx: &'ctx mut Ctx) -> Self { + fn wrap_mut(ctx: &'ctx mut Ctx) -> Self { return Self { ctx }; } } diff --git a/src/parent2node/mod.rs b/src/parent2node/mod.rs index ca6dfb6..2ecd347 100644 --- a/src/parent2node/mod.rs +++ b/src/parent2node/mod.rs @@ -1,3 +1,3 @@ pub mod clojure; -mod fixed_wrapper; -mod dynamic_wrappers; \ No newline at end of file +pub mod fixed_wrapper; +pub mod dynamic_wrappers; \ No newline at end of file