mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 13:30:48 +00:00
Make graphene_core no_std
This commit is contained in:
parent
90e465b35c
commit
09deee0c4d
12 changed files with 94 additions and 56 deletions
|
@ -1,4 +1,5 @@
|
|||
//#![feature(generic_associated_types)]
|
||||
pub mod value;
|
||||
pub use graphene_core::{generic, ops, structural};
|
||||
|
||||
#[cfg(feature = "caching")]
|
||||
pub mod caching;
|
||||
|
@ -6,3 +7,28 @@ pub mod caching;
|
|||
pub mod memo;
|
||||
|
||||
pub use graphene_core::*;
|
||||
|
||||
use dyn_any::{downcast_ref, DynAny, StaticType};
|
||||
use std::any::Any;
|
||||
pub type DynNode<'n, T> = &'n (dyn Node<'n, (), Output = T> + 'n);
|
||||
pub type DynAnyNode<'n> = &'n (dyn Node<'n, (), Output = &'n dyn DynAny<'n>> + 'n);
|
||||
|
||||
pub trait DynamicInput<'n> {
|
||||
fn set_kwarg_by_name(&mut self, name: &str, value: DynAnyNode<'n>);
|
||||
fn set_arg_by_index(&mut self, index: usize, value: DynAnyNode<'n>);
|
||||
}
|
||||
|
||||
pub trait AnyRef<'n, I: StaticType<'n>>: Node<'n, I> {
|
||||
fn any(&'n self, input: &'n dyn DynAny<'n>) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'n, T: Node<'n, I>, I: StaticType<'n>> AnyRef<'n, I> for T {
|
||||
fn any(&'n self, input: &'n dyn DynAny<'n>) -> Self::Output {
|
||||
self.eval(downcast_ref::<I>(input).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Node was evaluated with wrong input. The input has to be of type: {}",
|
||||
std::any::type_name::<I>(),
|
||||
)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
22
node-graph/gstd/src/value.rs
Normal file
22
node-graph/gstd/src/value.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use core::marker::PhantomData;
|
||||
pub use graphene_core::value::*;
|
||||
use graphene_core::Node;
|
||||
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
pub struct AnyRefNode<'n, N: Node<'n, I, Output = &'n O>, I, O>(
|
||||
&'n N,
|
||||
PhantomData<&'n I>,
|
||||
PhantomData<&'n O>,
|
||||
);
|
||||
impl<'n, N: Node<'n, I, Output = &'n O>, I, O: DynAny<'n>> Node<'n, I> for AnyRefNode<'n, N, I, O> {
|
||||
type Output = &'n (dyn DynAny<'n>);
|
||||
fn eval(&'n self, input: &'n I) -> Self::Output {
|
||||
let value: &O = self.0.eval(input);
|
||||
value
|
||||
}
|
||||
}
|
||||
impl<'n, N: Node<'n, I, Output = &'n O>, I, O: 'static> AnyRefNode<'n, N, I, O> {
|
||||
pub fn new(n: &'n N) -> AnyRefNode<'n, N, I, O> {
|
||||
AnyRefNode(n, PhantomData, PhantomData)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue