match self
Self
This commit is contained in:
parent
5cbabbdb37
commit
e7dc834c8b
@ -53,8 +53,8 @@ where
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
UnbalancedTree::Leaf => write!(f, "."),
|
||||
UnbalancedTree::Node(reference) => write!(f, "{}", reference),
|
||||
Self::Leaf => write!(f, "."),
|
||||
Self::Node(reference) => write!(f, "{}", reference),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,8 +109,8 @@ impl<'a, T: Monad<'a>, A: 'a + Clone> TraversibleBinaryTree<'a, T, A, Unbalanced
|
||||
{
|
||||
fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, UnbalancedData>>> {
|
||||
match self {
|
||||
UnbalancedTree::Leaf => None,
|
||||
UnbalancedTree::Node(reference) => Some(reference.clone()),
|
||||
Self::Leaf => None,
|
||||
Self::Node(reference) => Some(reference.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,16 +20,15 @@ type Oet<'a> = Option<EvalTree<'a>>;
|
||||
impl<'a> EvalTree<'a> {
|
||||
fn next(self) -> Oet<'a> {
|
||||
match self {
|
||||
EvalTree::Atom(f) => f(),
|
||||
EvalTree::Composite(etl, etr) => match *etl {
|
||||
EvalTree::Atom(f) => match f() {
|
||||
Some(newleft) => Some(EvalTree::Composite(Box::new(newleft), etr)),
|
||||
Self::Atom(f) => f(),
|
||||
Self::Composite(etl, etr) => match *etl {
|
||||
Self::Atom(f) => match f() {
|
||||
Some(newleft) => Some(Self::Composite(Box::new(newleft), etr)),
|
||||
None => Some(*etr),
|
||||
},
|
||||
EvalTree::Composite(etll, etlr) => Some(EvalTree::Composite(
|
||||
etll,
|
||||
Box::new(EvalTree::Composite(etlr, etr)),
|
||||
)),
|
||||
Self::Composite(etll, etlr) => {
|
||||
Some(Self::Composite(etll, Box::new(Self::Composite(etlr, etr))))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub type R = TestResults;
|
||||
impl R {
|
||||
pub fn unwrap(self) {
|
||||
match self {
|
||||
TestResults {
|
||||
Self {
|
||||
success,
|
||||
total,
|
||||
result: Err(e),
|
||||
|
@ -12,8 +12,8 @@ pub enum ResolutionError<L, P> {
|
||||
impl<L, P> ResolutionError<L, P> {
|
||||
pub fn map_parse<Px>(self, f: impl FnOnce(P) -> Px) -> ResolutionError<L, Px> {
|
||||
match self {
|
||||
ResolutionError::Lookup(l) => ResolutionError::Lookup(l),
|
||||
ResolutionError::Parse(p) => ResolutionError::Parse(f(p)),
|
||||
Self::Lookup(l) => ResolutionError::Lookup(l),
|
||||
Self::Parse(p) => ResolutionError::Parse(f(p)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,13 +40,13 @@ pub enum CastError<'a> {
|
||||
impl<'a> Display for CastError<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
CastError::Typeless(typeless_error) => {
|
||||
Self::Typeless(typeless_error) => {
|
||||
write!(f, "typeless cast error: {}", typeless_error)
|
||||
}
|
||||
CastError::AddressIndexOutOfBounds { index, length } => {
|
||||
Self::AddressIndexOutOfBounds { index, length } => {
|
||||
write!(f, "cast index out of bound: {}>={}", index, length)
|
||||
}
|
||||
CastError::AddressPointMismatch {
|
||||
Self::AddressPointMismatch {
|
||||
expected,
|
||||
received,
|
||||
index,
|
||||
|
@ -37,10 +37,10 @@ pub enum PairParseError<ErrorA: Error, ErrorB: Error> {
|
||||
impl<ErrorA: Error, ErrorB: Error> Display for PairParseError<ErrorA, ErrorB> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
PairParseError::A(error) => {
|
||||
Self::A(error) => {
|
||||
write!(f, "error while parsing first element of a pair: {}", error)
|
||||
}
|
||||
PairParseError::B(error) => {
|
||||
Self::B(error) => {
|
||||
write!(f, "error while parsing second element of a pair: {}", error)
|
||||
}
|
||||
}
|
||||
|
@ -1,162 +0,0 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::flow::traversible::*;
|
||||
use crate::func::*;
|
||||
use crate::rstd::fallible::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub type TPE<'a, Ctx, A> = TreeParseError<ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
|
||||
|
||||
pub type TreeFaiure<'a, Ctx, A> =
|
||||
ResolutionError<<Ctx as Context<'a>>::LookupError, TPE<'a, Ctx, A>>;
|
||||
|
||||
pub type SubsetWrapped<'a, Ctx, A> = FallibleWrapped<'a, Ctx, bool, TreeFaiure<'a, Ctx, A>>;
|
||||
|
||||
pub type SubsetMonad<'a, Ctx, A> = FallibleMonad<'a, Ctx, TreeFaiure<'a, Ctx, A>>;
|
||||
|
||||
pub fn subset_pure<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
|
||||
value: bool,
|
||||
) -> SubsetWrapped<'a, Ctx, A> {
|
||||
<SubsetMonad<'a, Ctx, A> as Pure>::pure(value)
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum NodeType {
|
||||
Rb,
|
||||
R,
|
||||
B,
|
||||
}
|
||||
|
||||
type RefData = (NodeType, Hash);
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
|
||||
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for BNode<'a, Ctx, A>
|
||||
{
|
||||
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
|
||||
(
|
||||
Rc::new(self.cl.clone()),
|
||||
Rc::new(self.cr.clone()),
|
||||
self.key.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
fn to_tree(
|
||||
self: Rc<Self>,
|
||||
) -> Rc<dyn TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, RefData>> {
|
||||
Rc::new(Nullable::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
|
||||
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RNode<'a, Ctx, A>
|
||||
{
|
||||
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
|
||||
(
|
||||
Rc::new(self.cl.clone()),
|
||||
Rc::new(self.cr.clone()),
|
||||
self.key.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
fn to_tree(
|
||||
self: Rc<Self>,
|
||||
) -> Rc<dyn TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, RefData>> {
|
||||
Rc::new(Nullable::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
|
||||
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RBNode<'a, Ctx, A>
|
||||
{
|
||||
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
|
||||
match self {
|
||||
RBNode::R(r) => r.split(),
|
||||
RBNode::B(b) => b.split(),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_tree(
|
||||
self: Rc<Self>,
|
||||
) -> Rc<dyn TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, RefData>> {
|
||||
Rc::new(Nullable::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
|
||||
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
|
||||
for Point<'a, Ctx, BNode<'a, Ctx, A>>
|
||||
{
|
||||
fn resolve(
|
||||
&self,
|
||||
) -> Wrap<
|
||||
'a,
|
||||
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
||||
SubsetMonad<'a, Ctx, A>,
|
||||
> {
|
||||
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(Ctx::stuff(self.resolve()), |resolved| {
|
||||
resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>
|
||||
})
|
||||
}
|
||||
|
||||
fn data(&self) -> RefData {
|
||||
(NodeType::B, self.point)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
|
||||
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
|
||||
for Point<'a, Ctx, RNode<'a, Ctx, A>>
|
||||
{
|
||||
fn resolve(
|
||||
&self,
|
||||
) -> Wrap<
|
||||
'a,
|
||||
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
||||
SubsetMonad<'a, Ctx, A>,
|
||||
> {
|
||||
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(Ctx::stuff(self.resolve()), |resolved| {
|
||||
resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>
|
||||
})
|
||||
}
|
||||
|
||||
fn data(&self) -> RefData {
|
||||
(NodeType::R, self.point)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
|
||||
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
|
||||
for Point<'a, Ctx, RBNode<'a, Ctx, A>>
|
||||
{
|
||||
fn resolve(
|
||||
&self,
|
||||
) -> Wrap<
|
||||
'a,
|
||||
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
||||
SubsetMonad<'a, Ctx, A>,
|
||||
> {
|
||||
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(Ctx::stuff(self.resolve()), |resolved| {
|
||||
resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>
|
||||
})
|
||||
}
|
||||
|
||||
fn data(&self) -> RefData {
|
||||
(NodeType::Rb, self.point)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, T: Mentionable<'a, Ctx>, D: 'a + PartialEq>
|
||||
TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, D> for Nullable<'a, Ctx, T>
|
||||
where
|
||||
Point<'a, Ctx, T>: TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, D>,
|
||||
{
|
||||
fn refer(
|
||||
&self,
|
||||
) -> Option<Rc<dyn TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, D>>> {
|
||||
match self {
|
||||
Nullable::Null(_) => None,
|
||||
Nullable::NotNull(point) => Some(Rc::new(point.clone())),
|
||||
}
|
||||
}
|
||||
}
|
@ -22,8 +22,8 @@ pub struct NullableFactory<F> {
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> {
|
||||
fn serialize(&self, serializer: &mut dyn Serializer) {
|
||||
serializer.write(match self {
|
||||
Nullable::Null(_) => &HASH_ZEROS,
|
||||
Nullable::NotNull(point) => &point.point,
|
||||
Self::Null(_) => &HASH_ZEROS,
|
||||
Self::NotNull(point) => &point.point,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -33,10 +33,10 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nul
|
||||
|
||||
fn factory(&self) -> Self::Fctr {
|
||||
match self {
|
||||
Nullable::Null(factory) => NullableFactory {
|
||||
Self::Null(factory) => NullableFactory {
|
||||
factory: factory.clone(),
|
||||
},
|
||||
Nullable::NotNull(point) => NullableFactory {
|
||||
Self::NotNull(point) => NullableFactory {
|
||||
factory: point.origin.factory(),
|
||||
},
|
||||
}
|
||||
@ -44,8 +44,8 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nul
|
||||
|
||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||
match self {
|
||||
Nullable::Null(_) => {}
|
||||
Nullable::NotNull(point) => points.take(point),
|
||||
Self::Null(_) => {}
|
||||
Self::NotNull(point) => points.take(point),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ impl WithLengthAndWidth<RenderedLong> {
|
||||
impl RenderedWide {
|
||||
fn any(self) -> RenderedAny {
|
||||
match self {
|
||||
RenderedWide::Common(common) => RenderedAny::Common(common),
|
||||
RenderedWide::Wide(vec) => RenderedAny::Wide(vec),
|
||||
Self::Common(common) => RenderedAny::Common(common),
|
||||
Self::Wide(vec) => RenderedAny::Wide(vec),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,8 +111,8 @@ impl RenderedWide {
|
||||
impl RenderedLong {
|
||||
fn any(self) -> RenderedAny {
|
||||
match self {
|
||||
RenderedLong::Common(common) => RenderedAny::Common(common),
|
||||
RenderedLong::Long(vec) => RenderedAny::Long(vec),
|
||||
Self::Common(common) => RenderedAny::Common(common),
|
||||
Self::Long(vec) => RenderedAny::Long(vec),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,10 +191,10 @@ impl RenderedCommon {
|
||||
impl RenderedCommon {
|
||||
fn rectangles(self, vec: &mut Vec<(usize, usize)>, t: usize, c: usize) {
|
||||
match self {
|
||||
RenderedCommon::Empty => {}
|
||||
RenderedCommon::Resolution => vec.push((t, c)),
|
||||
RenderedCommon::Event(_) => {}
|
||||
RenderedCommon::Action { rendered, .. } => rendered.rectangles(vec, t, c),
|
||||
Self::Empty => {}
|
||||
Self::Resolution => vec.push((t, c)),
|
||||
Self::Event(_) => {}
|
||||
Self::Action { rendered, .. } => rendered.rectangles(vec, t, c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ pub struct TraceBox {
|
||||
impl Trace {
|
||||
fn fmt_parallel(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Trace::Parallel(a, b) => {
|
||||
Self::Parallel(a, b) => {
|
||||
write!(f, "{} | {}", ParallelBox(a), ParallelBox(b))
|
||||
}
|
||||
trace => write!(f, "{}", trace),
|
||||
@ -29,7 +29,7 @@ impl Trace {
|
||||
|
||||
fn fmt_sequential(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Trace::Sequential { first, second } => {
|
||||
Self::Sequential { first, second } => {
|
||||
write!(f, "{} > {}", SequentialBox(first), SequentialBox(second))
|
||||
}
|
||||
trace => write!(f, "{}", trace),
|
||||
|
@ -18,15 +18,15 @@ enum TraceAny<'a> {
|
||||
impl Trace {
|
||||
fn any(&self) -> TraceAny<'_> {
|
||||
match self {
|
||||
Trace::Pure => TraceAny::Common(TraceCommon::Pure),
|
||||
Trace::InvolvesOneResolution => TraceAny::Common(TraceCommon::InvolvesOneResolution),
|
||||
Trace::Event(event) => TraceAny::Common(TraceCommon::Event(event)),
|
||||
Trace::Wrapped { name, trace } => TraceAny::Common(TraceCommon::Wrapped {
|
||||
Self::Pure => TraceAny::Common(TraceCommon::Pure),
|
||||
Self::InvolvesOneResolution => TraceAny::Common(TraceCommon::InvolvesOneResolution),
|
||||
Self::Event(event) => TraceAny::Common(TraceCommon::Event(event)),
|
||||
Self::Wrapped { name, trace } => TraceAny::Common(TraceCommon::Wrapped {
|
||||
name,
|
||||
trace: &trace.trace,
|
||||
}),
|
||||
Trace::Parallel(a, b) => TraceAny::Parallel(&a.trace, &b.trace),
|
||||
Trace::Sequential { first, second } => TraceAny::Sequential {
|
||||
Self::Parallel(a, b) => TraceAny::Parallel(&a.trace, &b.trace),
|
||||
Self::Sequential { first, second } => TraceAny::Sequential {
|
||||
first: &first.trace,
|
||||
second: &second.trace,
|
||||
},
|
||||
@ -67,9 +67,9 @@ fn from_parallel(
|
||||
impl<'a> TraceAny<'a> {
|
||||
fn render(&'a self) -> WithLengthAndWidth<RenderedAny> {
|
||||
match self {
|
||||
TraceAny::Common(common) => common.render().map(RenderedAny::Common),
|
||||
TraceAny::Parallel(a, b) => from_parallel(a, b).map(RenderedAny::Wide),
|
||||
TraceAny::Sequential { first, second } => {
|
||||
Self::Common(common) => common.render().map(RenderedAny::Common),
|
||||
Self::Parallel(a, b) => from_parallel(a, b).map(RenderedAny::Wide),
|
||||
Self::Sequential { first, second } => {
|
||||
from_sequential(first, second).map(RenderedAny::Long)
|
||||
}
|
||||
}
|
||||
@ -80,9 +80,9 @@ impl<'a> TraceAny<'a> {
|
||||
vec: &mut WithLengthAndWidth<Vec<WithLengthAndWidth<RenderedWide>>>,
|
||||
) {
|
||||
match self {
|
||||
TraceAny::Common(common) => common.render().map(RenderedWide::Common).push_into(vec),
|
||||
TraceAny::Parallel(a, b) => from_parallel(a, b).map(RenderedWide::Wide).push_into(vec),
|
||||
TraceAny::Sequential { first, second } => {
|
||||
Self::Common(common) => common.render().map(RenderedWide::Common).push_into(vec),
|
||||
Self::Parallel(a, b) => from_parallel(a, b).map(RenderedWide::Wide).push_into(vec),
|
||||
Self::Sequential { first, second } => {
|
||||
first.any().render_into_long(vec);
|
||||
second.any().render_into_long(vec);
|
||||
}
|
||||
@ -94,12 +94,12 @@ impl<'a> TraceAny<'a> {
|
||||
vec: &mut WithLengthAndWidth<Vec<WithLengthAndWidth<RenderedLong>>>,
|
||||
) {
|
||||
match self {
|
||||
TraceAny::Common(common) => common.render().map(RenderedLong::Common).push_into(vec),
|
||||
TraceAny::Parallel(a, b) => {
|
||||
Self::Common(common) => common.render().map(RenderedLong::Common).push_into(vec),
|
||||
Self::Parallel(a, b) => {
|
||||
a.any().render_into_wide(vec);
|
||||
b.any().render_into_wide(vec);
|
||||
}
|
||||
TraceAny::Sequential { first, second } => from_sequential(first, second)
|
||||
Self::Sequential { first, second } => from_sequential(first, second)
|
||||
.map(RenderedLong::Long)
|
||||
.push_into(vec),
|
||||
}
|
||||
@ -109,10 +109,10 @@ impl<'a> TraceAny<'a> {
|
||||
impl<'a> TraceCommon<'a> {
|
||||
fn render(&'a self) -> WithLengthAndWidth<RenderedCommon> {
|
||||
match self {
|
||||
TraceCommon::Pure => RenderedCommon::empty(),
|
||||
TraceCommon::InvolvesOneResolution => RenderedCommon::resolution(),
|
||||
TraceCommon::Event(event) => RenderedCommon::event(event),
|
||||
TraceCommon::Wrapped { name, trace } => trace.any().render().wrap(name),
|
||||
Self::Pure => RenderedCommon::empty(),
|
||||
Self::InvolvesOneResolution => RenderedCommon::resolution(),
|
||||
Self::Event(event) => RenderedCommon::event(event),
|
||||
Self::Wrapped { name, trace } => trace.any().render().wrap(name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user