Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions benzina-derive/src/join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use proc_macro2::{Span, TokenStream};
use quote::{ToTokens, quote};
use syn::{Ident, Index, Token, punctuated::Punctuated};

use crate::join::utils::tuple_from_tokenizables;

use self::{
quantity::Quantity,
utils::{Identifiable, NewIndexMap},
Expand Down Expand Up @@ -140,7 +142,7 @@ impl Transformation {
quote! {}
};

let or_insert = self.or_insert(&tuple_index_overwrites);
let or_insert_tokens = tuple_from_tokenizables(self.or_insert(&tuple_index_overwrites));
let accumulator = self
.entries
.iter()
Expand All @@ -157,7 +159,7 @@ impl Transformation {
#wrapper {
let mut accumulator = ::benzina::__private::indexmap::map::Entry::or_insert(
::benzina::__private::IndexMap::entry(&mut #accumulator_index, #id),
(#(#or_insert),*)
#or_insert_tokens
);
#(#accumulator)*
}
Expand Down
12 changes: 12 additions & 0 deletions benzina-derive/src/join/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ impl<T: ToTokens> ToTokens for Identifiable<T> {
});
}
}

pub(super) fn tuple_from_tokenizables<I>(tokenizables: I) -> TokenStream
where
I: IntoIterator<Item: ToTokens, IntoIter: ExactSizeIterator>,
{
let tokenizables = tokenizables.into_iter();
if tokenizables.len() == 0 {
quote! { () }
} else {
quote! { (#(#tokenizables),*,) }
}
}