Skip to content

Commit 9dd92ea

Browse files
bors[bot]toasteater
andauthored
Merge #668 #680
668: Fix minor mistakes in the Variant macros r=toasteater a=toasteater - Add missing import to `derive(ToVariant)` output - Use the correct variant name instead of `Ok` (leftover from `Result` impl) for `FromVariant` errors Close #665 680: Take self by value when deriving OwnedToVariant r=toasteater a=toasteater This was preventing the macro from working on types whose fields actually require OwnedToVariant. Co-authored-by: toasteater <48371905+toasteater@users.noreply.github.com>
3 parents e2fc055 + 8cb50b4 + 6584a26 commit 9dd92ea

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

gdnative-derive/src/variant/from.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) fn expand_from_variant(derive_data: DeriveData) -> Result<TokenStream
8787
#ref_var_ident_string_literals => {
8888
let #var_input_ident_iter = &__dict.get(&__keys.get(0));
8989
(#var_from_variants).map_err(|err| FVE::InvalidEnumVariant {
90-
variant: "Ok",
90+
variant: #ref_var_ident_string_literals,
9191
error: Box::new(err),
9292
})
9393
},

gdnative-derive/src/variant/to.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ pub(crate) fn expand_to_variant(
4848
let tokens = quote! {
4949
#ident::#var_ident #destructure_pattern => {
5050
let __dict = ::gdnative::core_types::Dictionary::new();
51-
let __key = ::gdnative::core_types::GodotString::from(#var_ident_string_literal).to_variant();
51+
let __key = ::gdnative::core_types::ToVariant::to_variant(
52+
&::gdnative::core_types::GodotString::from(#var_ident_string_literal)
53+
);
5254
let __value = #to_variant;
5355
__dict.insert(&__key, &__value);
54-
__dict.into_shared().to_variant()
56+
::gdnative::core_types::ToVariant::to_variant(&__dict.into_shared())
5557
}
5658
};
5759
Ok(tokens)
5860
}).collect::<Result<Vec<_>,syn::Error>>()?;
5961

6062
quote! {
61-
match &self {
63+
match #to_variant_receiver {
6264
#( #match_arms ),*
6365
}
6466
}

gdnative/tests/ui/variant_pass.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ pub struct Foo {
3636
skip_from: String,
3737
}
3838

39+
#[derive(OwnedToVariant)]
40+
pub struct Owned;
41+
42+
#[derive(OwnedToVariant)]
43+
pub struct Bar {
44+
owned: Owned,
45+
}
46+
3947
fn main() {}

0 commit comments

Comments
 (0)