mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
* Rename the 'Identity' node to 'Passthrough' internally * Rename the 'Memoize' node to 'Cache' internally * Let skip_impl proto nodes auto-generate as document node definitions * Remove the wrapper 'Passthrough' node from document_node_definitions.rs * Remove the wrapper 'Cache' node from document_node_definitions.rs * Remove the wrapper 'Monitor' node from document_node_definitions.rs * Remove the wrapper 'Noise Pattern' node from document_node_definitions.rs * Remove the wrapper 'Brush' node from document_node_definitions.rs * Remove the wrapper 'Transform' node from document_node_definitions.rs * Code review improvements * Rename Cache node back to Memoize * More code review
32 lines
1.0 KiB
Rust
32 lines
1.0 KiB
Rust
use core_types::{Ctx, ExtractFootprint, ops::Convert, transform::Footprint};
|
|
use std::marker::PhantomData;
|
|
|
|
// Re-export TypeNode from core-types for convenience
|
|
pub use core_types::ops::TypeNode;
|
|
|
|
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
|
|
#[node_macro::node(category("General"), skip_impl)]
|
|
fn passthrough<'i, T: 'i + Send>(_: impl Ctx, content: T) -> T {
|
|
content
|
|
}
|
|
|
|
#[node_macro::node(category(""), skip_impl)]
|
|
fn into<'i, T: 'i + Send + Into<O>, O: 'i + Send>(_: impl Ctx, value: T, _out_ty: PhantomData<O>) -> O {
|
|
value.into()
|
|
}
|
|
|
|
#[node_macro::node(category(""), skip_impl)]
|
|
async fn convert<'i, T: 'i + Send + Convert<O, C>, O: 'i + Send, C: 'i + Send>(ctx: impl Ctx + ExtractFootprint, value: T, converter: C, _out_ty: PhantomData<O>) -> O {
|
|
value.convert(*ctx.try_footprint().unwrap_or(&Footprint::DEFAULT), converter).await
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
|
|
#[test]
|
|
pub fn passthrough_node() {
|
|
assert_eq!(passthrough((), &4), &4);
|
|
}
|
|
}
|