Fix automatic Into node insertion (#3087)
Fix automatic into node insertion
This commit is contained in:
parent
354bf93364
commit
bb364c92ad
|
|
@ -1,3 +1,5 @@
|
||||||
|
use graphene_core_shaders::Ctx;
|
||||||
|
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
|
@ -41,28 +43,9 @@ impl<'i, N: for<'a> Node<'a, I> + Clone, I: 'i> Clone for TypeNode<N, I, <N as N
|
||||||
}
|
}
|
||||||
impl<'i, N: for<'a> Node<'a, I> + Copy, I: 'i> Copy for TypeNode<N, I, <N as Node<'i, I>>::Output> {}
|
impl<'i, N: for<'a> Node<'a, I> + Copy, I: 'i> Copy for TypeNode<N, I, <N as Node<'i, I>>::Output> {}
|
||||||
|
|
||||||
// Into
|
#[node_macro::node(skip_impl)]
|
||||||
pub struct IntoNode<O>(PhantomData<O>);
|
fn into<'i, T: 'i + Send + Into<O>, O: 'i + Send>(_: impl Ctx, value: T, _out_ty: PhantomData<O>) -> O {
|
||||||
impl<O> IntoNode<O> {
|
value.into()
|
||||||
pub const fn new() -> Self {
|
|
||||||
Self(PhantomData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<O> Default for IntoNode<O> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'input, I: 'input, O: 'input> Node<'input, I> for IntoNode<O>
|
|
||||||
where
|
|
||||||
I: Into<O> + Sync + Send,
|
|
||||||
{
|
|
||||||
type Output = dyn_any::DynFuture<'input, O>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn eval(&'input self, input: I) -> Self::Output {
|
|
||||||
Box::pin(async move { input.into() })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`Convert`] trait allows for conversion between Rust primitive numeric types.
|
/// The [`Convert`] trait allows for conversion between Rust primitive numeric types.
|
||||||
|
|
@ -122,25 +105,9 @@ impl_convert!(u128);
|
||||||
impl_convert!(isize);
|
impl_convert!(isize);
|
||||||
impl_convert!(usize);
|
impl_convert!(usize);
|
||||||
|
|
||||||
// Convert
|
#[node_macro::node(skip_impl)]
|
||||||
pub struct ConvertNode<O>(PhantomData<O>);
|
fn convert<'i, T: 'i + Send + Convert<O>, O: 'i + Send>(_: impl Ctx, value: T, _out_ty: PhantomData<O>) -> O {
|
||||||
impl<_O> ConvertNode<_O> {
|
value.convert()
|
||||||
pub const fn new() -> Self {
|
|
||||||
Self(core::marker::PhantomData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<_O> Default for ConvertNode<_O> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'input, I: 'input + Convert<_O> + Sync + Send, _O: 'input> Node<'input, I> for ConvertNode<_O> {
|
|
||||||
type Output = ::dyn_any::DynFuture<'input, _O>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn eval(&'input self, input: I) -> Self::Output {
|
|
||||||
Box::pin(async move { input.convert() })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -153,13 +153,14 @@ where
|
||||||
{
|
{
|
||||||
type Output = DynFuture<'input, O>;
|
type Output = DynFuture<'input, O>;
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[track_caller]
|
||||||
fn eval(&'input self, input: I) -> Self::Output {
|
fn eval(&'input self, input: I) -> Self::Output {
|
||||||
{
|
{
|
||||||
let node_name = self.node.node_name();
|
let node_name = self.node.node_name();
|
||||||
let input = Box::new(input);
|
let input = Box::new(input);
|
||||||
let future = self.node.eval(input);
|
let future = self.node.eval(input);
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let out = dyn_any::downcast(future.await).unwrap_or_else(|e| panic!("DowncastBothNode Input {e} in: \n{node_name}"));
|
let out = dyn_any::downcast(future.await).unwrap_or_else(|e| panic!("DowncastBothNode wrong output type: {e} in: \n{node_name}"));
|
||||||
*out
|
*out
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -294,17 +294,23 @@ mod node_registry_macros {
|
||||||
(from: $from:ty, to: $to:ty) => {
|
(from: $from:ty, to: $to:ty) => {
|
||||||
(
|
(
|
||||||
ProtoNodeIdentifier::new(concat!["graphene_core::ops::IntoNode<", stringify!($to), ">"]),
|
ProtoNodeIdentifier::new(concat!["graphene_core::ops::IntoNode<", stringify!($to), ">"]),
|
||||||
|_| {
|
|mut args| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let node = graphene_core::ops::IntoNode::<$to>::new();
|
let node = graphene_core::ops::IntoNode::new(
|
||||||
let any: DynAnyNode<$from, _, _> = graphene_std::any::DynAnyNode::new(node);
|
graphene_std::any::downcast_node::<Context, $from>(args.pop().unwrap()),
|
||||||
|
graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)),
|
||||||
|
);
|
||||||
|
let any: DynAnyNode<Context, $to, _> = graphene_std::any::DynAnyNode::new(node);
|
||||||
Box::new(any) as TypeErasedBox
|
Box::new(any) as TypeErasedBox
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
let node = graphene_core::ops::IntoNode::<$to>::new();
|
let node = graphene_core::ops::IntoNode::new(
|
||||||
let mut node_io = NodeIO::<'_, $from>::to_async_node_io(&node, vec![]);
|
graphene_std::any::PanicNode::<Context, core::pin::Pin<Box<dyn core::future::Future<Output = $from> + Send>>>::new(),
|
||||||
node_io.call_argument = future!(<$from as StaticType>::Static);
|
graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)),
|
||||||
|
);
|
||||||
|
let params = vec![fn_type_fut!(Context, $from)];
|
||||||
|
let node_io = NodeIO::<'_, Context>::to_async_node_io(&node, params);
|
||||||
node_io
|
node_io
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -333,17 +339,20 @@ mod node_registry_macros {
|
||||||
(from: $from:ty, to: $to:ty) => {
|
(from: $from:ty, to: $to:ty) => {
|
||||||
(
|
(
|
||||||
ProtoNodeIdentifier::new(concat!["graphene_core::ops::ConvertNode<", stringify!($to), ">"]),
|
ProtoNodeIdentifier::new(concat!["graphene_core::ops::ConvertNode<", stringify!($to), ">"]),
|
||||||
|_| {
|
|mut args| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let node = graphene_core::ops::ConvertNode::<$to>::new();
|
let node = graphene_core::ops::ConvertNode::new(graphene_std::any::downcast_node::<Context, $from>(args.pop().unwrap()),
|
||||||
let any: DynAnyNode<$from, _, _> = graphene_std::any::DynAnyNode::new(node);
|
graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)) );
|
||||||
|
let any: DynAnyNode<Context, $to, _> = graphene_std::any::DynAnyNode::new(node);
|
||||||
Box::new(any) as TypeErasedBox
|
Box::new(any) as TypeErasedBox
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
let node = graphene_core::ops::ConvertNode::<$to>::new();
|
let node = graphene_core::ops::ConvertNode::new(graphene_std::any::PanicNode::<Context, core::pin::Pin<Box<dyn core::future::Future<Output = $from> + Send>>>::new(),
|
||||||
let mut node_io = NodeIO::<'_, $from>::to_async_node_io(&node, vec![]);
|
|
||||||
node_io.call_argument = future!(<$from as StaticType>::Static);
|
graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)) );
|
||||||
|
let params = vec![fn_type_fut!(Context, $from)];
|
||||||
|
let node_io = NodeIO::<'_, Context>::to_async_node_io(&node, params);
|
||||||
node_io
|
node_io
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
|
||||||
(
|
(
|
||||||
NodeId(i as u64),
|
NodeId(i as u64),
|
||||||
match inputs.len() {
|
match inputs.len() {
|
||||||
1 if false => {
|
1 => {
|
||||||
let input = inputs.iter().next().unwrap();
|
let input = inputs.iter().next().unwrap();
|
||||||
let input_ty = input.nested_type();
|
let input_ty = input.nested_type();
|
||||||
|
|
||||||
|
|
@ -87,6 +87,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
|
||||||
// manual_composition: Some(fn_input.clone()),
|
// manual_composition: Some(fn_input.clone()),
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(proto_node),
|
implementation: DocumentNodeImplementation::ProtoNode(proto_node),
|
||||||
visible: true,
|
visible: true,
|
||||||
|
manual_composition: Some(concrete!(Context)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue