Fix ambiguous constructors of context wrappers

This commit is contained in:
Andrew Golovashevich 2025-12-27 18:06:16 +03:00
parent 2136192cf1
commit df0e32b7d5
5 changed files with 65 additions and 16 deletions

View File

@ -20,7 +20,7 @@ impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeContextFromContext<&'
} }
impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeContextFromContext<&'ctx mut Ctx> { 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 { return Self {
ctx, ctx,
dir: initialDirection, dir: initialDirection,

View File

@ -23,9 +23,17 @@ pub struct FixedRightDirectedBinaryTreeContextFromContext<CtxRef> {
} }
macro_rules! _constructor { macro_rules! _constructor {
($name:ident $($mut:tt)?) => { ($name:ident) => {
impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx> { impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx Ctx> {
pub fn wrap(ctx: &'ctx $($mut)? Ctx) -> Self { 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 }; return Self { ctx };
} }
} }

View File

@ -37,10 +37,10 @@ struct DynamicParent2NodeGetterClojureFromDirectedContext<CtxRef, NodeRef> {
} }
macro_rules! _constructor { macro_rules! _constructor {
($name:ident $direction:ident $($mut:tt)?) => { ($name:ident $direction:ident) => {
impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx, Ctx::NodeRef> { impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx Ctx, Ctx::NodeRef> {
pub fn wrap_not_root( pub fn wrapNode(
ctx: &'ctx $($mut)? Ctx, node: Ctx::NodeRef, direction: $direction ctx: &'ctx Ctx, node: Ctx::NodeRef, direction: $direction
) -> Self { ) -> Self {
return Self { return Self {
dir: Some(direction), dir: Some(direction),
@ -48,6 +48,39 @@ macro_rules! _constructor {
node: _NodeOrNothing { node: ManuallyDrop::new(node) } 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: () }
};
}
} }
}; };
} }

View File

@ -19,14 +19,14 @@ macro_rules! _mut_switch {
macro_rules! _struct { macro_rules! _struct {
($name:ident) => { ($name:ident) => {
struct $name<CtxRef, NodeRef> { pub struct $name<CtxRef, NodeRef> {
ctx: CtxRef, ctx: CtxRef,
node: NodeRef, node: NodeRef,
} }
}; };
} }
struct FixedRootParent2NodeGetterClojureFromContext<NodeRef> { pub struct FixedRootParent2NodeGetterClojureFromContext<NodeRef> {
ctx: NodeRef, ctx: NodeRef,
} }
_struct!(FixedLeftParent2NodeGetterClojureFromContext); _struct!(FixedLeftParent2NodeGetterClojureFromContext);
@ -35,9 +35,17 @@ _struct!(FixedForwardParent2NodeGetterClojureFromDirectedContext);
_struct!(FixedOppositeParent2NodeGetterClojureFromDirectedContext); _struct!(FixedOppositeParent2NodeGetterClojureFromDirectedContext);
macro_rules! _constructor { macro_rules! _constructor {
($name:ident $($mut:tt)?) => { ($name:ident) => {
impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx, Ctx::NodeRef> { impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx Ctx, Ctx::NodeRef> {
pub fn wrap(ctx: &'ctx $($mut)? Ctx, node: Ctx::NodeRef) -> Self { 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 }; return Self { ctx, node };
} }
} }
@ -53,7 +61,7 @@ impl<'ctx, Ctx: NodeRefContainer + BinaryTreeRootGetter>
} }
impl<'ctx, Ctx: NodeRefContainer> FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx> { 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 }; return Self { ctx };
} }
} }

View File

@ -1,3 +1,3 @@
pub mod clojure; pub mod clojure;
mod fixed_wrapper; pub mod fixed_wrapper;
mod dynamic_wrappers; pub mod dynamic_wrappers;