codegen/function: body future handles ownership of slice argument#1580
Conversation
|
CI is failing, but I don't think it is related with the changes: |
| let is_slice = matches!(type_, library::Type::CArray(_)); | ||
|
|
||
| if *c_par.nullable { | ||
| if is_slice { |
There was a problem hiding this comment.
Would also support a nullable slice while at it :)
There was a problem hiding this comment.
AFAIK, nullable annotation on array still produces a &[] (and not a Option<&[]>). So to_vec still applies
There was a problem hiding this comment.
AFAIK, nullable annotation on array still produces a &[] (and not a Option<&[]>). So to_vec still applies
That is an issue that should be fixed separately, see #1551
There was a problem hiding this comment.
However, that PR is still not merged.
If I change my code assuming I can have Option<&[]>, that is:
if *c_par.nullable {
...
} else if (is_slice) {
...
} ...I'd end up still having a bug generated code until that PR kicks in.
Isn't it better to change the ifs order in #1551 where the logic actually changes?
(P.S: why having Option<&[]>. That's not rust idiomatic. the current behavior (if I am not mistaken): &[] even when array is annotated as nullable makes sense in the generated rust type
There was a problem hiding this comment.
Sometimes there is a difference in behaviour between passing None and &[]. See #1133 (comment) but agree, that can be done in the other PR.
Currently, the future body generated is something like:
both approaches fail to compile as:
.mapdoes not exist forslicetype (it is not anOption).clone()does not really give ownership of the data slice, ascloneonly copies the wide-pointer.staticlifetime (and that's the reason why the code in the generator performs acloneorto_ownedin the first place).This PR aims to handle the case of slice argument