Flag adapter nodes and register them by identifier

This commit is contained in:
Dennis Kobert committed 2026-12-05 12:15:08 +01:00
1 parent 9c9b393420
commit cc1c343bf3
6 files changed
+102 -35

No files matched your search

+7
View File
@@ -838,8 +838,14 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
footprint_invariant,
forwards_input,
inject_scope,
adapter,
..
} = attributes.flags;
let adapter = match adapter {
Some(AdapterKind::Conversion) => quote!(Some(gcore::registry::AdapterKind::Conversion)),
Some(AdapterKind::Rank) => quote!(Some(gcore::registry::AdapterKind::Rank)),
None => quote!(None),
};
let asynchronous = parsed.is_async;
let version = attributes.version.unwrap_or(1);
// A node returning a `Destructure` struct records its fields as output connectors
@@ -1053,6 +1059,7 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
forwards_input: #forwards_input,
inject_scope: #inject_scope,
asynchronous: #asynchronous,
adapter: #adapter,
},
version: #version,
output_fields: #output_fields,
+29 -1
View File
@@ -54,6 +54,15 @@ pub(crate) struct NodeFlags {
pub(crate) no_partial: bool,
/// Set on the `Destructure` derive's generated extractor nodes, which take the struct rather than an `Item` or `List`. Not parsed from source.
pub(crate) destructure_extractor: bool,
/// Whether type resolution may insert this node on an edge, and how it changes the wire.
pub(crate) adapter: Option<AdapterKind>,
}
/// Mirrors `core_types::registry::AdapterKind`, which this proc-macro crate cannot depend on.
#[derive(Debug, Clone, Copy)]
pub(crate) enum AdapterKind {
Conversion,
Rank,
}
#[derive(Debug, Default, Clone)]
@@ -557,6 +566,25 @@ impl Parse for NodeFnAttributes {
// Example usage:
// #[node_macro::node(..., forwards_input, ...)]
"forwards_input" => set_flag(&mut flags.forwards_input, meta, "forwards_input")?,
// Marks the node as an adapter that type resolution may insert on an edge, either converting the wire's element type or changing its rank.
//
// Example usage:
// #[node_macro::node(..., adapter(conversion), ...)]
// #[node_macro::node(..., adapter(rank), ...)]
"adapter" => {
let meta = meta.require_list()?;
if flags.adapter.is_some() {
return Err(Error::new_spanned(meta, "Multiple 'adapter' attributes are not allowed"));
}
let kind: Ident = meta
.parse_args()
.map_err(|_| Error::new_spanned(meta, "Expected 'conversion' or 'rank' for 'adapter', e.g., adapter(rank)"))?;
flags.adapter = Some(match kind.to_string().as_str() {
"conversion" => AdapterKind::Conversion,
"rank" => AdapterKind::Rank,
_ => return Err(Error::new_spanned(kind, "Expected 'conversion' or 'rank' for 'adapter', e.g., adapter(rank)")),
});
}
// Instructs the preprocessor to make this node available as a scope.
// Other nodes can then access it with `#[scope(node::IDENTIFIER)]`.
//
@@ -604,7 +632,7 @@ impl Parse for NodeFnAttributes {
indoc!(
r#"
Unsupported attribute in `node`.
Supported attributes are 'category', 'name', 'icon', 'path', 'skip_impl', 'inspector', 'cfg', 'memoize', 'footprint_invariant', 'forwards_input', 'inject_scope', 'placeholder', 'no_partial', and 'version'.
Supported attributes are 'category', 'name', 'icon', 'path', 'skip_impl', 'inspector', 'cfg', 'memoize', 'footprint_invariant', 'forwards_input', 'adapter', 'inject_scope', 'placeholder', 'no_partial', and 'version'.
Example usage:
#[node_macro::node(..., name("Test Node"), ...)]
"#