Skip to content

Commit

Permalink
lazy tmp code
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Sep 22, 2023
1 parent cb26545 commit 1d7059c
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 176 deletions.
11 changes: 7 additions & 4 deletions core/src/declare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{context::BuildCtx, prelude::Pipe, state::ModifyScope};
use crate::{context::BuildCtx, pipe::Pipe, state::ModifyScope};
use rxrust::ops::box_it::BoxOp;
use std::convert::Infallible;

Expand All @@ -21,7 +21,7 @@ pub trait DeclareBuilder {
/// The type use to store the init value of the field when declare a object.
pub enum DeclareInit<V> {
Value(V),
Pipe(Pipe<V>),
Pipe(Box<dyn Pipe<Value = V>>),
}

type ValueStream<V> = BoxOp<'static, (ModifyScope, V), Infallible>;
Expand Down Expand Up @@ -52,9 +52,12 @@ impl<V, U: From<V>> DeclareFrom<V, ()> for DeclareInit<U> {
fn declare_from(value: V) -> Self { Self::Value(value.into()) }
}

impl<V: 'static, U: From<V> + 'static> DeclareFrom<Pipe<V>, Pipe<()>> for DeclareInit<U> {
impl<P: Pipe + 'static, V> DeclareFrom<P, &dyn Pipe<Value = ()>> for DeclareInit<V>
where
P::Value: From<V> + 'static,
{
#[inline]
fn declare_from(value: Pipe<V>) -> Self { Self::Pipe(value.map(U::from)) }
fn declare_from(value: P) -> Self { Self::Pipe(Box::new(value.map(|v| v.into()))) }
}

/// struct help the generate code have better type hint.
Expand Down
Loading

0 comments on commit 1d7059c

Please sign in to comment.