mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-09 05:58:55 +00:00
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:
parent
b55c62beb5
commit
db16a5968b
1 changed files with 3 additions and 5 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue