Skip to content
Merged
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
44 changes: 24 additions & 20 deletions benzina-derive/src/join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,21 @@ impl Transformation {
#name: #entry
}
});
let map_closure = if is_result {
let output = quote! {
#output_type {
#(#entries),*
}
};
let map_closure = if self.is_nested_result() {
quote! {
|item| ::benzina::__private::std::result::Result::Ok::<
#output_type,
::benzina::__private::diesel::result::Error
>(#output_type {
#(#entries),*
})
>(#output)
}
} else {
quote! {
|item| #output_type {
#(#entries),*
}
|item| #output
}
};
let iterator = quote! {
Expand All @@ -214,20 +215,19 @@ impl Transformation {
};
match quantity {
Quantity::MaybeOne => {
let item = quote! {
::benzina::__private::std::iter::Iterator::next(
&mut #iterator
)
};
if is_result {
quote! {
::benzina::__private::std::option::Option::transpose(
::benzina::__private::std::iter::Iterator::next(
&mut #iterator
)
#item
)?
}
} else {
quote! {
::benzina::__private::std::iter::Iterator::next(
&mut #iterator
)
}
item
}
}
Quantity::One | Quantity::AssumeOne => {
Expand Down Expand Up @@ -269,13 +269,17 @@ impl Transformation {

fn is_result(&self) -> bool {
match self.quantity {
Quantity::AtLeastZero | Quantity::AtLeastOne => true,
_ => self.entries.iter().any(|(_, entry)| match entry {
NestedOrNot::Nested(nested) => nested.is_result(),
NestedOrNot::Not(_) => false,
}),
Quantity::One | Quantity::AssumeOne => true,
_ => self.is_nested_result(),
}
}

fn is_nested_result(&self) -> bool {
self.entries.iter().any(|(_, entry)| match entry {
NestedOrNot::Nested(nested) => nested.is_result(),
NestedOrNot::Not(_) => false,
})
}
}

impl NoTransformation {
Expand Down