From a048fc44b7844b774eaf1d5d3600adde31461498 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Mon, 5 Apr 2021 15:46:36 +0200 Subject: [PATCH] Properties are now registered in order of declaration --- gdnative-derive/src/native_script.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gdnative-derive/src/native_script.rs b/gdnative-derive/src/native_script.rs index 00813d605..6b76cbd19 100644 --- a/gdnative-derive/src/native_script.rs +++ b/gdnative-derive/src/native_script.rs @@ -1,7 +1,6 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use std::collections::HashMap; use syn::spanned::Spanned; use syn::{Data, DeriveInput, Fields, Ident, Meta, MetaList, NestedMeta, Path, Stmt, Type}; @@ -13,7 +12,7 @@ pub(crate) struct DeriveData { pub(crate) base: Type, pub(crate) register_callback: Option, pub(crate) user_data: Type, - pub(crate) properties: HashMap, + pub(crate) properties: Vec<(Ident, PropertyAttrArgs)>, pub(crate) no_constructor: bool, } @@ -188,7 +187,7 @@ fn parse_derive_input(input: &DeriveInput) -> Result { }; // Find all fields with a `#[property]` attribute - let mut properties = HashMap::new(); + let mut properties = Vec::new(); if let Fields::Named(names) = &struct_data.fields { for field in &names.named { @@ -232,7 +231,7 @@ fn parse_derive_input(input: &DeriveInput) -> Result { .ident .clone() .ok_or_else(|| syn::Error::new(field.ident.span(), "Fields should be named"))?; - properties.insert(ident, builder.done()); + properties.push((ident, builder.done())); } } };