mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-24 16:13:44 +00:00
Add ::IDENTITY
to node macro to return a ProtoNodeIdentifier
that is always a &'static str
(#2842)
* fix warnings on master * make the `ProtoNodeIdentifier` of a Node be accessible and always a borrowed `&'static str` * always generate `node_name::identifier()`, even with `skip_impl` * make `FrontendNodeType` use Cow * remove broken `DocumentNodeDefinition`s for old GPU nodes * don't reexport `graphic_element` in it's entirety, only data structures * adjust everything to use the new `node_name::identifier()` * fixup imports for wasm * turn identifier fn into a constant
This commit is contained in:
parent
4a83067081
commit
69ed80b79b
20 changed files with 213 additions and 523 deletions
|
@ -12,7 +12,7 @@ pub mod debug;
|
|||
pub mod extract_xy;
|
||||
pub mod generic;
|
||||
pub mod gradient;
|
||||
mod graphic_element;
|
||||
pub mod graphic_element;
|
||||
pub mod instances;
|
||||
pub mod logic;
|
||||
pub mod math;
|
||||
|
@ -35,7 +35,7 @@ pub use blending::*;
|
|||
pub use context::*;
|
||||
pub use ctor;
|
||||
pub use dyn_any::{StaticTypeSized, WasmNotSend, WasmNotSync};
|
||||
pub use graphic_element::*;
|
||||
pub use graphic_element::{Artboard, ArtboardGroupTable, GraphicElement, GraphicGroupTable};
|
||||
pub use memo::MemoHash;
|
||||
pub use num_traits;
|
||||
pub use raster::Color;
|
||||
|
@ -161,7 +161,7 @@ where
|
|||
|
||||
pub trait NodeInputDecleration {
|
||||
const INDEX: usize;
|
||||
fn identifier() -> &'static str;
|
||||
fn identifier() -> ProtoNodeIdentifier;
|
||||
type Result;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::{Node, WasmNotSend};
|
|||
use dyn_any::DynFuture;
|
||||
use std::future::Future;
|
||||
use std::hash::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
@ -49,6 +50,10 @@ impl<T, CachedNode> MemoNode<T, CachedNode> {
|
|||
}
|
||||
}
|
||||
|
||||
pub mod memo {
|
||||
pub const IDENTIFIER: crate::ProtoNodeIdentifier = crate::ProtoNodeIdentifier::new("graphene_core::memo::MemoNode");
|
||||
}
|
||||
|
||||
/// Caches the output of a given Node and acts as a proxy.
|
||||
/// In contrast to the regular `MemoNode`. This node ignores all input.
|
||||
/// Using this node might result in the document not updating properly,
|
||||
|
@ -98,6 +103,10 @@ impl<T, I, CachedNode> ImpureMemoNode<I, T, CachedNode> {
|
|||
}
|
||||
}
|
||||
|
||||
pub mod impure_memo {
|
||||
pub const IDENTIFIER: crate::ProtoNodeIdentifier = crate::ProtoNodeIdentifier::new("graphene_core::memo::ImpureMemoNode");
|
||||
}
|
||||
|
||||
/// Stores both what a node was called with and what it returned.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IORecord<I, O> {
|
||||
|
@ -142,7 +151,10 @@ impl<I, T, N> MonitorNode<I, T, N> {
|
|||
}
|
||||
}
|
||||
|
||||
use std::hash::{Hash, Hasher};
|
||||
pub mod monitor {
|
||||
pub const IDENTIFIER: crate::ProtoNodeIdentifier = crate::ProtoNodeIdentifier::new("graphene_core::memo::MonitorNode");
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub struct MemoHash<T: Hash> {
|
||||
hash: u64,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Node, NodeIO, NodeIOTypes, Type, WasmNotSend};
|
||||
use crate::{Node, NodeIO, NodeIOTypes, ProtoNodeIdentifier, Type, WasmNotSend};
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
@ -103,11 +103,11 @@ pub enum RegistryValueSource {
|
|||
Scope(&'static str),
|
||||
}
|
||||
|
||||
type NodeRegistry = LazyLock<Mutex<HashMap<String, Vec<(NodeConstructor, NodeIOTypes)>>>>;
|
||||
type NodeRegistry = LazyLock<Mutex<HashMap<ProtoNodeIdentifier, Vec<(NodeConstructor, NodeIOTypes)>>>>;
|
||||
|
||||
pub static NODE_REGISTRY: NodeRegistry = LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
pub static NODE_METADATA: LazyLock<Mutex<HashMap<String, NodeMetadata>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||
pub static NODE_METADATA: LazyLock<Mutex<HashMap<ProtoNodeIdentifier, NodeMetadata>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub type DynFuture<'n, T> = Pin<Box<dyn Future<Output = T> + 'n + Send>>;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::any::TypeId;
|
||||
|
||||
pub use std::borrow::Cow;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! concrete {
|
||||
|
@ -128,12 +129,37 @@ impl std::fmt::Debug for NodeIOTypes {
|
|||
pub struct ProtoNodeIdentifier {
|
||||
pub name: Cow<'static, str>,
|
||||
}
|
||||
|
||||
impl From<String> for ProtoNodeIdentifier {
|
||||
fn from(value: String) -> Self {
|
||||
Self { name: Cow::Owned(value) }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for ProtoNodeIdentifier {
|
||||
fn from(s: &'static str) -> Self {
|
||||
ProtoNodeIdentifier { name: Cow::Borrowed(s) }
|
||||
}
|
||||
}
|
||||
|
||||
impl ProtoNodeIdentifier {
|
||||
pub const fn new(name: &'static str) -> Self {
|
||||
ProtoNodeIdentifier { name: Cow::Borrowed(name) }
|
||||
}
|
||||
|
||||
pub const fn with_owned_string(name: String) -> Self {
|
||||
ProtoNodeIdentifier { name: Cow::Owned(name) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ProtoNodeIdentifier {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.name.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate_type_descriptor_names<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Cow<'static, str>, D::Error> {
|
||||
use serde::Deserialize;
|
||||
|
||||
|
@ -306,6 +332,13 @@ impl Type {
|
|||
Self::Future(output) => output.replace_nested(f),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_cow_string(&self) -> Cow<'static, str> {
|
||||
match self {
|
||||
Type::Generic(name) => name.clone(),
|
||||
_ => Cow::Owned(self.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn format_type(ty: &str) -> String {
|
||||
|
@ -343,19 +376,3 @@ impl std::fmt::Display for Type {
|
|||
write!(f, "{}", result)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for ProtoNodeIdentifier {
|
||||
fn from(s: &'static str) -> Self {
|
||||
ProtoNodeIdentifier { name: Cow::Borrowed(s) }
|
||||
}
|
||||
}
|
||||
|
||||
impl ProtoNodeIdentifier {
|
||||
pub const fn new(name: &'static str) -> Self {
|
||||
ProtoNodeIdentifier { name: Cow::Borrowed(name) }
|
||||
}
|
||||
|
||||
pub const fn with_owned_string(name: String) -> Self {
|
||||
ProtoNodeIdentifier { name: Cow::Owned(name) }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue