feat!: return unit type instead of wkt::Empty#1635
Conversation
This is the normal mapping for `wkt::Empty` (or `google.protobuf.Empty`) when used as a return type for a unary RPC.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1635 +/- ##
=======================================
Coverage 95.72% 95.72%
=======================================
Files 43 43
Lines 1825 1825
=======================================
Hits 1747 1747
Misses 78 78 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dbolduc
left a comment
There was a problem hiding this comment.
Approved, but consider my suggestions :)
| {{#ReturnsEmpty}} | ||
| let _ : wkt::Empty = self.inner.execute( | ||
| builder, | ||
| {{#PathInfo.Codec.HasBody}}Some(req{{Codec.BodyAccessor}}){{/PathInfo.Codec.HasBody}} | ||
| {{^PathInfo.Codec.HasBody}}None::<gaxi::http::NoBody>{{/PathInfo.Codec.HasBody}}, | ||
| options, | ||
| ).await?; | ||
| Ok(()) | ||
| {{/ReturnsEmpty}} | ||
| {{^ReturnsEmpty}} | ||
| self.inner.execute( | ||
| builder, | ||
| {{#PathInfo.Codec.HasBody}}Some(req{{Codec.BodyAccessor}}){{/PathInfo.Codec.HasBody}} | ||
| {{^PathInfo.Codec.HasBody}}None::<gaxi::http::NoBody>{{/PathInfo.Codec.HasBody}}, | ||
| options, | ||
| ).await | ||
| {{/ReturnsEmpty}} |
There was a problem hiding this comment.
Maybe too cute, but consider:
self.inner.execute(
builder,
{{#PathInfo.Codec.HasBody}}Some(req{{Codec.BodyAccessor}}){{/PathInfo.Codec.HasBody}}
{{^PathInfo.Codec.HasBody}}None::<gaxi::http::NoBody>{{/PathInfo.Codec.HasBody}},
options,
).await
{{#ReturnsEmpty}}
.map(|_| ())
{{/ReturnsEmpty}}
There was a problem hiding this comment.
Hmm... because the execute function is generic, we have to say .map(|_: wkt::Empty| ()) It is a bit weird. If I was typing the code that is not how I would do it, but it does express what we are doing.
| traits (e.g. `std::clone::Clone`) making the call ambiguous. | ||
| Using `*self.0.stub` makes the call not-ambiguous. | ||
| }} | ||
| {{#ReturnsEmpty}} |
There was a problem hiding this comment.
optional: we could avoid all of the ReturnsEmpty blocks (except for the one in transport.rs) if we add a ReturnType to the message1 codec, that is QualifiedName == "wkt::Empty" ? "()" : QualifiedName
up to you if you think that would be nicer.
Footnotes
-
It probably makes more sense on the method codec, though. ↩
This is the normal mapping for
wkt::Empty(orgoogle.protobuf.Empty)when used as a return type for a unary RPC.
Fixes #1509