Skip to content

Commit 06c0083

Browse files
committed
fix(join): add comma at the end of tuple statement to let rust recognize a _one elemnt tuple_
1 parent 435216c commit 06c0083

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

benzina-derive/src/join/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use proc_macro2::{Span, TokenStream};
44
use quote::{ToTokens, quote};
55
use syn::{Ident, Index, Token, punctuated::Punctuated};
66

7+
use crate::join::utils::tuple_from_vec;
8+
79
use self::{
810
quantity::Quantity,
911
utils::{Identifiable, NewIndexMap},
@@ -140,7 +142,7 @@ impl Transformation {
140142
quote! {}
141143
};
142144

143-
let or_insert = self.or_insert(&tuple_index_overwrites);
145+
let or_insert_tokens = tuple_from_vec(&self.or_insert(&tuple_index_overwrites));
144146
let accumulator = self
145147
.entries
146148
.iter()
@@ -157,7 +159,7 @@ impl Transformation {
157159
#wrapper {
158160
let mut accumulator = ::benzina::__private::indexmap::map::Entry::or_insert(
159161
::benzina::__private::IndexMap::entry(&mut #accumulator_index, #id),
160-
(#(#or_insert),*)
162+
#or_insert_tokens
161163
);
162164
#(#accumulator)*
163165
}

benzina-derive/src/join/utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ impl<T: ToTokens> ToTokens for Identifiable<T> {
2525
});
2626
}
2727
}
28+
29+
pub(super) fn tuple_from_vec(vec: &[impl ToTokens]) -> TokenStream {
30+
if vec.is_empty() {
31+
quote! { () }
32+
} else {
33+
quote! { (#(#vec),*,) }
34+
}
35+
}

0 commit comments

Comments
 (0)