Skip to content

Commit

Permalink
dsl_util: forward upper-bounded expect_*_arguments() to common function
Browse files Browse the repository at this point in the history
I'm going to add keyword arguments handling, and I want to deduplicate check
for unsupported arguments.
  • Loading branch information
yuja committed May 29, 2024
1 parent 49d9b45 commit cda477d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/src/dsl_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ 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(())
}

/// Extracts exactly N required arguments.
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.
Expand Down

0 comments on commit cda477d

Please sign in to comment.