Re: [PATCH v2] rust: add procedural macro for declaring configfs attributes
From: Malte Wechter
Date: Wed Jun 10 2026 - 10:48:43 EST
On 6/10/26 12:05 PM, Gary Guo wrote:
On Wed Jun 10, 2026 at 10:15 AM BST, Malte Wechter wrote:
What make_static_ident is doing I think is quite hacky. I'd rather not havingI believe it is nice to keep the identifiers unique, especially if you+Instead of creating identifers like this, just scope them properly so that
+ Ok(ConfigfsAttrs {
+ container,
+ data,
+ child,
+ attributes,
+ })
+ }
+}
+
+fn make_static_ident<T: ToTokens>(ty: &T, suffix: &str) -> syn::Ident {
+ let raw_id = quote! { #ty }.to_string();
+
+ // Sanitizing syn::Type::Path, this is safe since it is
+ // only used as the identifier.
+ let normalized = raw_id
+ .split("::")
+ .map(|s| String::from(s.trim()))
+ .reduce(|a, b| format!("{a}_{b}"))
+ .expect("Cannot be empty")
+ .to_uppercase()
+ .replace(|c: char| !c.is_alphanumeric(), "_");
+
+ Ident::new(&format!("{}_{}", normalized, suffix), ty.span())
+}
+
+pub(crate) fn configfs_attrs(cfs_attrs: ConfigfsAttrs) -> proc_macro2::TokenStream {
+ let (container_ty, data_ty) = (&cfs_attrs.container, &cfs_attrs.data);
+
+ let data_tp_ident = make_static_ident(data_ty, "TPE");
+ let data_attr_ident = make_static_ident(data_ty, "ATTR_LIST");
a fixed identifier is used without colliding.
have many fields
you can easily differentiate them.
them. Plus, the identifiers are not seen by users anyway.
Best,
Gary
I will simplify the naming of the static variables greatly (removing make_static_ident), but still generate unique identifiers.
Best regards,
Malte