Add Destruct macro and trait for automatically acessing struct fields

This commit is contained in:
Dennis Kobert
2025-04-14 08:15:26 +02:00
parent 0531769c41
commit 2e97e81290
6 changed files with 126 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ pub struct NodeMetadata {
pub description: &'static str,
pub properties: Option<&'static str>,
pub context_features: Vec<ContextFeature>,
pub output_fields: &'static [StructField],
}
// Translation struct between macro and definition
@@ -36,6 +37,26 @@ pub struct FieldMetadata {
pub unit: Option<&'static str>,
}
#[derive(Clone, Debug)]
pub struct StructField {
pub name: &'static str,
pub node_path: &'static str,
pub ty: Type,
}
pub trait Destruct {
fn fields(&self) -> &'static [StructField];
}
impl<T> Destruct for &T
where
T: Default,
{
fn fields(&self) -> &'static [StructField] {
&[]
}
}
#[derive(Clone, Debug)]
pub enum RegistryWidgetOverride {
None,