dsl_util: forward upper-bounded expect_*_arguments() to common function

I'm going to add keyword arguments handling, and I want to deduplicate check
for unsupported arguments.
This commit is contained in:
Yuya Nishihara 2024-05-26 17:01:54 +09:00
parent b55c62beb5
commit db16a5968b

View file

@ -54,7 +54,7 @@ pub struct FunctionCallNode<'i, T> {
impl<'i, T> FunctionCallNode<'i, T> {
/// Ensures that no arguments passed.
pub fn expect_no_arguments(&self) -> Result<(), InvalidArguments<'i>> {
let [] = self.expect_exact_arguments()?;
let ([], []) = self.expect_arguments()?;
Ok(())
}
@ -62,10 +62,8 @@ impl<'i, T> FunctionCallNode<'i, T> {
pub fn expect_exact_arguments<const N: usize>(
&self,
) -> Result<&[ExpressionNode<'i, T>; N], InvalidArguments<'i>> {
self.args
.as_slice()
.try_into()
.map_err(|_| self.invalid_arguments_count(N, Some(N)))
let (args, []) = self.expect_arguments()?;
Ok(args)
}
/// Extracts N required arguments and remainders.