Closed lasantosr closed 2 months ago
Thanks for opening this - agreed it would be much more user friendly. I think the related question is if you'd want to keep the borrowed option with Into<Cow<...>>
or just take the simpler route and just require Into<OwnedType>
.
The latter would make async-stripe
codegen much simpler (no lifetimes, no special handling of borrowed types, plus opportunity for codegen to deduplicate these request params with response types). Having to clone unnecessarily sometimes hopefully shouldn't impact performance compared to network requests (some precedence for the simpler route in how other huge generated crates like the aws sdk do it).
The other minor concern to check for would be impact on compile times - one advantage of purely borrowed types is minimal generated code for Drop
impls, which show up a surprising amount when using tools like cargo bloat
or cargo llvm-lines
to investigate compile time.
I mentioned Cow
just to make use of the already-traked lifetimes and avoid unnecessary clones when not required, but I agree that the completely owned type would be better than just references, at least on usability. Didn't know about the Drop
implications tho, but I'd happily spend some more time compiling and less time dealing with the limitations.
I'll try to familiarize with the codegen crate to check if I can make some PR, but I'm not sure if I will get familiar enough to implement that refactor.
I will close this since it has landed in next and we don't plan on backporting.
Is your feature request related to a problem? Please describe.
I'm using
next
branch.When building requests, for example
CreateWebhookEndpoint
, we must pass a reference to the fields in order to construct them.This is inconvenient for two reasons:
We can't implement
From
other types we own to the requests or build the requests in any isolated method, because we can't return values referenced by the function and we can't transfer the ownership. Pseudo-code example:We can't build the values only when required, because borrowed value does not live long enough. Pseudo-code example:
Describe the solution you'd like
Update the signature of the methods to require
impl Into<Cow<'a, {type}>>
and the Builders properties to haveCow<'a, {type}>
instead of&'a {type}
, allowing both previous scenario and the ones defined above.For example this method:
Would allow both ways:
Describe alternatives you've considered
There's no alternative other than avoiding those scenarios.
Additional context
No response