From db16a5968ba1251e00de1d836caa0d8f4ad8d777 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 26 May 2024 17:01:54 +0900 Subject: [PATCH] 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. --- lib/src/dsl_util.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/src/dsl_util.rs b/lib/src/dsl_util.rs index 5ae298245..89659e405 100644 --- a/lib/src/dsl_util.rs +++ b/lib/src/dsl_util.rs @@ -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( &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.