Skip to content

Commit c785dce

Browse files
committed
Allow optional variadic arguments for methods/functions
1 parent 45f71b3 commit c785dce

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/macros/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub fn build_arg_parser<'a>(
188188
None
189189
});
190190

191-
if rest_optional && !arg.nullable && arg.default.is_none() {
191+
if rest_optional && !arg.nullable && arg.default.is_none() && !arg.variadic {
192192
bail!(
193193
"Parameter `{}` must be a variant of `Option` or have a default value as it is optional.",
194194
arg.name

src/types/zval.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,18 @@ impl<'a> FromZvalMut<'a> for &'a mut Zval {
718718
Some(zval)
719719
}
720720
}
721+
722+
impl<'a> FromZvalMut<'a> for &'a [&'a Zval] {
723+
const TYPE: DataType = DataType::Array;
724+
725+
fn from_zval_mut(zval: &'a mut Zval) -> Option<Self> {
726+
// Check if the input Zval is an array and convert it into a slice of references
727+
if let Some(a) = zval.array(){
728+
// Collect references to each element in the array
729+
let slice: Vec<&'a Zval> = a.values().collect();
730+
Some(Box::leak(slice.into_boxed_slice()))
731+
} else {
732+
None
733+
}
734+
}
735+
}

0 commit comments

Comments
 (0)