mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
Implement Upcasting without nightly support (#825)
This commit is contained in:
parent
4ec600957c
commit
ae7affda74
4 changed files with 49 additions and 6 deletions
|
@ -2,11 +2,11 @@ use dyn_any::StaticType;
|
|||
|
||||
use dyn_clone::DynClone;
|
||||
|
||||
use dyn_any::DynAny;
|
||||
use dyn_any::{DynAny, Upcast};
|
||||
|
||||
pub type Value = Box<dyn ValueTrait>;
|
||||
|
||||
pub trait ValueTrait: DynAny<'static> + std::fmt::Debug + DynClone {}
|
||||
pub trait ValueTrait: DynAny<'static> + Upcast<dyn DynAny<'static>> + std::fmt::Debug + DynClone {}
|
||||
|
||||
pub trait IntoValue: Sized + ValueTrait + 'static {
|
||||
fn into_any(self) -> Value {
|
||||
|
@ -14,7 +14,7 @@ pub trait IntoValue: Sized + ValueTrait + 'static {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: 'static + StaticType + std::fmt::Debug + PartialEq + Clone> ValueTrait for T {}
|
||||
impl<T: 'static + StaticType + Upcast<dyn DynAny<'static>> + std::fmt::Debug + PartialEq + Clone> ValueTrait for T {}
|
||||
|
||||
impl<T: 'static + ValueTrait> IntoValue for T {}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(trait_upcasting)]
|
||||
pub mod node_registry;
|
||||
|
||||
pub mod document;
|
||||
|
|
|
@ -13,6 +13,8 @@ use graphene_std::raster::Image;
|
|||
use crate::proto::Type;
|
||||
use crate::proto::{ConstructionArgs, NodeIdentifier, ProtoNode, ProtoNodeInput, Type::Concrete};
|
||||
|
||||
use dyn_any::Upcast;
|
||||
|
||||
type NodeConstructor = fn(ProtoNode, &FixedSizeStack<TypeErasedNode<'static>>);
|
||||
|
||||
//TODO: turn into hasmap
|
||||
|
@ -186,7 +188,8 @@ static NODE_REGISTRY: &[(NodeIdentifier<'static>, NodeConstructor)] = &[
|
|||
|proto_node, stack| {
|
||||
stack.push_fn(|_nodes| {
|
||||
if let ConstructionArgs::Value(value) = proto_node.construction_args {
|
||||
let node = FnNode::new(move |_| value.clone() as Any<'static>);
|
||||
let node = FnNode::new(move |_| value.clone().up_box() as Any<'static>);
|
||||
|
||||
node.into_type_erased()
|
||||
} else {
|
||||
unreachable!()
|
||||
|
@ -202,7 +205,7 @@ static NODE_REGISTRY: &[(NodeIdentifier<'static>, NodeConstructor)] = &[
|
|||
|proto_node, stack| {
|
||||
stack.push_fn(|_nodes| {
|
||||
if let ConstructionArgs::Value(value) = proto_node.construction_args {
|
||||
let node = FnNode::new(move |_| value.clone() as Any<'static>);
|
||||
let node = FnNode::new(move |_| value.clone().up_box() as Any<'static>);
|
||||
node.into_type_erased()
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue