Fix formatting of previous commit

This commit is contained in:
Keavon Chambers
2022-08-04 00:18:42 -07:00
parent d09f023618
commit 0c2dbd411b
11 changed files with 226 additions and 234 deletions

View File

@@ -3,98 +3,93 @@ use core::marker::PhantomData;
use crate::Node;
pub struct ComposeNode<'n, Inter, First, Second> {
first: &'n First,
second: &'n Second,
_phantom: PhantomData<&'n Input>,
_phantom2: PhantomData<Inter>,
first: &'n First,
second: &'n Second,
_phantom: PhantomData<&'n Input>,
_phantom2: PhantomData<Inter>,
}
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input>
for ComposeNode<'n, Input, Inter, First, Second>
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input> for ComposeNode<'n, Input, Inter, First, Second>
where
First: Node<'n, Input, Output = Inter>,
Second: Node<'n, Inter>, /*+ Node<<First as Node<Input>>::Output<'n>>*/
First: Node<'n, Input, Output = Inter>,
Second: Node<'n, Inter>, /*+ Node<<First as Node<Input>>::Output<'n>>*/
{
type Output = <Second as Node<'n, Inter>>::Output;
type Output = <Second as Node<'n, Inter>>::Output;
fn eval(&'n self, input: Input) -> Self::Output {
// evaluate the first node with the given input
// and then pipe the result from the first computation
// into the second node
let arg: Inter = self.first.eval(input);
self.second.eval(arg)
}
fn eval(&'n self, input: Input) -> Self::Output {
// evaluate the first node with the given input
// and then pipe the result from the first computation
// into the second node
let arg: Inter = self.first.eval(input);
self.second.eval(arg)
}
}
impl<'n, Input, Inter, FIRST, SECOND> ComposeNode<'n, Input, Inter, FIRST, SECOND>
where
FIRST: Node<'n, Input>,
FIRST: Node<'n, Input>,
{
pub const fn new(first: &'n FIRST, second: &'n SECOND) -> Self {
ComposeNode::<'n, Input, Inter, FIRST, SECOND> {
first,
second,
_phantom: PhantomData,
_phantom2: PhantomData,
}
}
pub const fn new(first: &'n FIRST, second: &'n SECOND) -> Self {
ComposeNode::<'n, Input, Inter, FIRST, SECOND> {
first,
second,
_phantom: PhantomData,
_phantom2: PhantomData,
}
}
}
#[repr(C)]
pub struct ComposeNodeOwned<'n, Input, Inter, FIRST, SECOND> {
first: FIRST,
second: SECOND,
_phantom: PhantomData<&'n Input>,
_phantom2: PhantomData<Inter>,
first: FIRST,
second: SECOND,
_phantom: PhantomData<&'n Input>,
_phantom2: PhantomData<Inter>,
}
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input>
for ComposeNodeOwned<'n, Input, Inter, First, Second>
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input> for ComposeNodeOwned<'n, Input, Inter, First, Second>
where
First: Node<'n, Input, Output = Inter>,
Second: Node<'n, Inter>,
First: Node<'n, Input, Output = Inter>,
Second: Node<'n, Inter>,
{
type Output = <Second as Node<'n, Inter>>::Output;
type Output = <Second as Node<'n, Inter>>::Output;
fn eval(&'n self, input: Input) -> Self::Output {
// evaluate the first node with the given input
// and then pipe the result from the first computation
// into the second node
let arg: Inter = self.first.eval(input);
self.second.eval(arg)
}
fn eval(&'n self, input: Input) -> Self::Output {
// evaluate the first node with the given input
// and then pipe the result from the first computation
// into the second node
let arg: Inter = self.first.eval(input);
self.second.eval(arg)
}
}
impl<'n, Input, Inter, First: 'n, Second> ComposeNodeOwned<'n, Input, Inter, First, Second>
where
First: Node<'n, Input, Output = Inter>,
First: Node<'n, Input, Output = Inter>,
{
#[cfg(feature = "nightly")]
pub const fn new(first: First, second: Second) -> Self {
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
first,
second,
_phantom: PhantomData,
_phantom2: PhantomData,
}
}
#[cfg(not(feature = "nightly"))]
pub fn new(first: First, second: Second) -> Self {
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
first,
second,
_phantom: PhantomData,
_phantom2: PhantomData,
}
}
#[cfg(feature = "nightly")]
pub const fn new(first: First, second: Second) -> Self {
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
first,
second,
_phantom: PhantomData,
_phantom2: PhantomData,
}
}
#[cfg(not(feature = "nightly"))]
pub fn new(first: First, second: Second) -> Self {
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
first,
second,
_phantom: PhantomData,
_phantom2: PhantomData,
}
}
}
pub trait After<I>: Sized {
fn after<'n, First: Node<'n, I>>(
&'n self,
first: &'n First,
) -> ComposeNode<'n, I, <First as Node<'n, I>>::Output, First, Self> {
ComposeNode::new(first, self)
}
fn after<'n, First: Node<'n, I>>(&'n self, first: &'n First) -> ComposeNode<'n, I, <First as Node<'n, I>>::Output, First, Self> {
ComposeNode::new(first, self)
}
}
impl<Second: for<'n> Node<'n, I>, I> After<I> for Second {}