Skip to content

Commit

Permalink
Allow optional variadic arguments for methods/functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yoramdelangen committed Nov 12, 2024
1 parent 45f71b3 commit c785dce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/macros/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn build_arg_parser<'a>(
None
});

if rest_optional && !arg.nullable && arg.default.is_none() {
if rest_optional && !arg.nullable && arg.default.is_none() && !arg.variadic {
bail!(
"Parameter `{}` must be a variant of `Option` or have a default value as it is optional.",
arg.name
Expand Down
15 changes: 15 additions & 0 deletions src/types/zval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,18 @@ impl<'a> FromZvalMut<'a> for &'a mut Zval {
Some(zval)
}
}

impl<'a> FromZvalMut<'a> for &'a [&'a Zval] {
const TYPE: DataType = DataType::Array;

fn from_zval_mut(zval: &'a mut Zval) -> Option<Self> {
// Check if the input Zval is an array and convert it into a slice of references
if let Some(a) = zval.array(){
// Collect references to each element in the array
let slice: Vec<&'a Zval> = a.values().collect();
Some(Box::leak(slice.into_boxed_slice()))
} else {
None
}
}
}

0 comments on commit c785dce

Please sign in to comment.