Compare commits
No commits in common. "5f0927c94aa837095247f0209424d5b356223ef6" and "b3c6f1defdf3d7a82788061f39ca196dc3e616fa" have entirely different histories.
5f0927c94a
...
b3c6f1defd
@ -5,7 +5,6 @@ use std::ops::Deref;
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Generic implementation of a [Mentionable] for [Atomic]s.
|
/// Generic implementation of a [Mentionable] for [Atomic]s.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct AtomicObject<A: Atomic> {
|
pub struct AtomicObject<A: Atomic> {
|
||||||
atomic: A,
|
atomic: A,
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ pub struct StackNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
|
|||||||
/// Reference comes first due to being inlineable.
|
/// Reference comes first due to being inlineable.
|
||||||
pub rest: Stack<'a, Ctx, A>,
|
pub rest: Stack<'a, Ctx, A>,
|
||||||
/// Unlike the original implementation in Python, doesn't default to using Point.
|
/// Unlike the original implementation in Python, doesn't default to using Point.
|
||||||
pub element: A,
|
pub element: Rc<A>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type representing a stack, an alias to a [Nullable] of a [StackNode].
|
/// Type representing a stack, an alias to a [Nullable] of a [StackNode].
|
||||||
@ -90,7 +90,8 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for StackNodeFa
|
|||||||
return Err(StackParseError::Point(ppe));
|
return Err(StackParseError::Point(ppe));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let element = match self
|
let element = Rc::new(
|
||||||
|
match self
|
||||||
.element_factory
|
.element_factory
|
||||||
.deserialize(deserializer, resolver, addresses)
|
.deserialize(deserializer, resolver, addresses)
|
||||||
{
|
{
|
||||||
@ -98,7 +99,8 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for StackNodeFa
|
|||||||
Err(epe) => {
|
Err(epe) => {
|
||||||
return Err(StackParseError::Element(epe));
|
return Err(StackParseError::Element(epe));
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
);
|
||||||
Ok(StackNode { rest, element })
|
Ok(StackNode { rest, element })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,9 +113,9 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for StackNodeFa
|
|||||||
pub type StackFaiure<'a, Ctx, A> = ResolutionFailure<'a, Ctx, StackNode<'a, Ctx, A>>;
|
pub type StackFaiure<'a, Ctx, A> = ResolutionFailure<'a, Ctx, StackNode<'a, Ctx, A>>;
|
||||||
|
|
||||||
/// See [`StackVecWrapped`].
|
/// See [`StackVecWrapped`].
|
||||||
pub type StackVecResult<'a, Ctx, A> = Result<Vec<A>, StackFaiure<'a, Ctx, A>>;
|
pub type StackVecResult<'a, Ctx, A> = Result<Vec<Rc<A>>, StackFaiure<'a, Ctx, A>>;
|
||||||
|
|
||||||
/// See [`ExtStackClone::vec`].
|
/// See [`ExtStack::vec`].
|
||||||
pub type StackVecWrapped<'a, Ctx, A> = Wrapped<'a, Ctx, StackVecResult<'a, Ctx, A>>;
|
pub type StackVecWrapped<'a, Ctx, A> = Wrapped<'a, Ctx, StackVecResult<'a, Ctx, A>>;
|
||||||
|
|
||||||
/// Extention trait with helper methods for [Stack]s.
|
/// Extention trait with helper methods for [Stack]s.
|
||||||
@ -126,12 +128,6 @@ pub trait ExtStack<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>: Mentionable<'
|
|||||||
///
|
///
|
||||||
/// Note: consumes the stack. For non-consuming version do `.clone()` before adding.
|
/// Note: consumes the stack. For non-consuming version do `.clone()` before adding.
|
||||||
fn add(self, element: A) -> Self;
|
fn add(self, element: A) -> Self;
|
||||||
}
|
|
||||||
|
|
||||||
/// Extention trait with helper methods for [Stack]s.
|
|
||||||
pub trait ExtStackClone<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone>:
|
|
||||||
Mentionable<'a, Ctx>
|
|
||||||
{
|
|
||||||
/// Collect all the elements into a [`Vec`].
|
/// Collect all the elements into a [`Vec`].
|
||||||
fn vec(self) -> StackVecWrapped<'a, Ctx, A>;
|
fn vec(self) -> StackVecWrapped<'a, Ctx, A>;
|
||||||
}
|
}
|
||||||
@ -147,16 +143,11 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Sta
|
|||||||
Nullable::NotNull(
|
Nullable::NotNull(
|
||||||
StackNode {
|
StackNode {
|
||||||
rest: self,
|
rest: self,
|
||||||
element,
|
element: Rc::new(element),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> ExtStackClone<'a, Ctx, A>
|
|
||||||
for Stack<'a, Ctx, A>
|
|
||||||
{
|
|
||||||
fn vec(self) -> StackVecWrapped<'a, Ctx, A> {
|
fn vec(self) -> StackVecWrapped<'a, Ctx, A> {
|
||||||
Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack {
|
Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack {
|
||||||
Nullable::Null(_) => Ctx::pure(ControlFlow::Break(Ok(vec))),
|
Nullable::Null(_) => Ctx::pure(ControlFlow::Break(Ok(vec))),
|
||||||
|
Loading…
Reference in New Issue
Block a user