From 04ff3288a7d1eb89000eaec97f4d57271f00e198 Mon Sep 17 00:00:00 2001 From: Yoshinori Tanimura Date: Thu, 16 Feb 2023 19:41:21 +0900 Subject: [PATCH] get_owned for select without boxed variant --- CHANGELOG.md | 1 + ruststep-derive/src/select.rs | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8507eb6da..0f2616d9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ In addition to original Keep-a-Changelog, we use following rules: ### Changed - Remove `field` attr from enumerations. +- Recursive `get_owned` for select type without boxed variant. ### Fixed - Deseialize `Option::Some`. diff --git a/ruststep-derive/src/select.rs b/ruststep-derive/src/select.rs index b27031f65..62e4e4248 100644 --- a/ruststep-derive/src/select.rs +++ b/ruststep-derive/src/select.rs @@ -16,6 +16,7 @@ struct Input { variant_into_exprs: Vec, holder_types: Vec, holder_exprs: Vec, + place_holders: Vec, } impl Input { @@ -37,8 +38,10 @@ impl Input { let mut holder_types = Vec::new(); let mut variant_exprs = Vec::new(); let mut variant_into_exprs = Vec::new(); + let mut place_holders = Vec::new(); for var in &e.variants { let HolderAttr { place_holder, .. } = HolderAttr::parse(&var.attrs); + place_holders.push(place_holder); assert_eq!(var.fields.len(), 1); for f in &var.fields { @@ -81,6 +84,7 @@ impl Input { variant_into_exprs, holder_types, holder_exprs, + place_holders, } } @@ -214,18 +218,28 @@ impl Input { holder_types, table, variant_into_exprs, + place_holders, .. } = self; let ruststep = ruststep_crate(); let itertools = itertools_crate(); let mut vars = Vec::new(); - let mut exprs = Vec::new(); let mut holders = Vec::::new(); - for ((var, holder), expr) in variants.iter().zip(holder_types).zip(variant_into_exprs) { - if let FieldType::Boxed(path) = holder.clone().try_into().unwrap() { + let mut exprs = Vec::new(); + for (((var, holder), expr), place_holder) in variants + .iter() + .zip(holder_types) + .zip(variant_into_exprs) + .zip(place_holders) + { + if *place_holder { vars.push(var); - holders.push(path.as_ref().clone().into()); exprs.push(expr); + if let FieldType::Boxed(path) = holder.clone().try_into().unwrap() { + holders.push(path.as_ref().clone().into()); + } else { + holders.push(holder.clone()); + } } }