Skip to content

Commit

Permalink
get_owned for select without boxed variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ytanimura committed Feb 16, 2023
1 parent ba24ab2 commit 04ff328
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
22 changes: 18 additions & 4 deletions ruststep-derive/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Input {
variant_into_exprs: Vec<TokenStream2>,
holder_types: Vec<syn::Type>,
holder_exprs: Vec<TokenStream2>,
place_holders: Vec<bool>,
}

impl Input {
Expand All @@ -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 {
Expand Down Expand Up @@ -81,6 +84,7 @@ impl Input {
variant_into_exprs,
holder_types,
holder_exprs,
place_holders,
}
}

Expand Down Expand Up @@ -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::<syn::Type>::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());
}
}
}

Expand Down

0 comments on commit 04ff328

Please sign in to comment.