From 6817b7831b586ba82b35973cbe739355928e204f Mon Sep 17 00:00:00 2001 From: toyboot4e Date: Sat, 30 Jul 2022 16:14:48 +0900 Subject: [PATCH] clean `#[inspect(is_modified)]` --- fyrox-core-derive/README.md | 6 +++++- fyrox-core-derive/src/inspect/args.rs | 6 +++--- fyrox-core-derive/src/inspect/utils.rs | 5 ++--- fyrox-core-derive/tests/it/inspect.rs | 2 +- src/scene/transform.rs | 18 +++++++++--------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fyrox-core-derive/README.md b/fyrox-core-derive/README.md index 5b7611651..bee1ca2db 100644 --- a/fyrox-core-derive/README.md +++ b/fyrox-core-derive/README.md @@ -1,3 +1,7 @@ # fyrox-core-derive -Provides the `#[derive(Visit)]` macro, which implements `fyrox::core::visitor::Visit`. +This crate provides with some derive macros: + +- `#[derive(Visit)]` +- `#[derive(Inspect)]` +- `#[derive(Reflect)]` diff --git a/fyrox-core-derive/src/inspect/args.rs b/fyrox-core-derive/src/inspect/args.rs index a81623efa..cfc07bcc3 100644 --- a/fyrox-core-derive/src/inspect/args.rs +++ b/fyrox-core-derive/src/inspect/args.rs @@ -100,11 +100,11 @@ pub struct FieldArgs { #[darling(default)] pub description: Option, - /// `#[inspect(getter = "")]` + /// `#[inspect(is_modified = )]` /// - /// True if the value has been modified. + /// Method call syntax. It returns true if the value has been modified. #[darling(default)] - pub is_modified: Option, + pub is_modified: Option, } impl FieldArgs { diff --git a/fyrox-core-derive/src/inspect/utils.rs b/fyrox-core-derive/src/inspect/utils.rs index 89f26d1c8..f011cca5c 100644 --- a/fyrox-core-derive/src/inspect/utils.rs +++ b/fyrox-core-derive/src/inspect/utils.rs @@ -206,7 +206,7 @@ fn quote_field_prop( let getter = match &field.getter { // use custom getter function to retrieve the target reference Some(getter) => { - quote! { (#field_ref).#getter } + quote! { #field_ref.#getter } } // default: get reference of the field None => field_ref.clone(), @@ -247,8 +247,7 @@ fn quote_field_prop( let is_modified = match field.is_modified.as_ref() { Some(getter) => { - let getter: Path = parse_str(getter).expect("can't parse `is_modified` as a path"); - quote! { #field_ref.#getter() } + quote! { #field_ref.#getter } } None => quote! { false }, }; diff --git a/fyrox-core-derive/tests/it/inspect.rs b/fyrox-core-derive/tests/it/inspect.rs index dfb6e7e78..3477f2b52 100644 --- a/fyrox-core-derive/tests/it/inspect.rs +++ b/fyrox-core-derive/tests/it/inspect.rs @@ -310,7 +310,7 @@ fn inspect_with_custom_getter() { #[test] fn inspect_modified() { #[derive(Inspect, Reflect)] - struct S(#[inspect(is_modified = "clone")] bool); + struct S(#[inspect(is_modified = "clone()")] bool); let s = S(true); assert_eq!( diff --git a/src/scene/transform.rs b/src/scene/transform.rs index 6667474bc..b62aa4539 100644 --- a/src/scene/transform.rs +++ b/src/scene/transform.rs @@ -73,7 +73,7 @@ pub struct Transform { #[inspect( deref, description = "Local scale of the transform", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] local_scale: TemplateVariable>, @@ -81,7 +81,7 @@ pub struct Transform { #[inspect( deref, description = "Local position of the transform", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] local_position: TemplateVariable>, @@ -89,7 +89,7 @@ pub struct Transform { #[inspect( deref, description = "Local rotation of the transform", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] local_rotation: TemplateVariable>, @@ -97,7 +97,7 @@ pub struct Transform { #[inspect( deref, description = "Pre rotation of the transform. Applied before local rotation.", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] pre_rotation: TemplateVariable>, @@ -105,7 +105,7 @@ pub struct Transform { #[inspect( deref, description = "Post rotation of the transform. Applied after local rotation.", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] post_rotation: TemplateVariable>, @@ -113,7 +113,7 @@ pub struct Transform { #[inspect( deref, description = "Rotation offset of the transform.", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] rotation_offset: TemplateVariable>, @@ -121,7 +121,7 @@ pub struct Transform { #[inspect( deref, description = "Rotation pivot of the transform.", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] rotation_pivot: TemplateVariable>, @@ -129,7 +129,7 @@ pub struct Transform { #[inspect( deref, description = "Scale offset of the transform.", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] scaling_offset: TemplateVariable>, @@ -137,7 +137,7 @@ pub struct Transform { #[inspect( deref, description = "Scale pivot of the transform.", - is_modified = "is_modified" + is_modified = "is_modified()" )] #[reflect(deref)] scaling_pivot: TemplateVariable>,