pub struct FunArgs {
pub values: Vec<Type>,
pub needed: usize,
}Expand description
Represents function argument types with optional parameter support.
This type allows defining functions that have both required and optional parameters.
The needed field specifies how many arguments are required, while values contains
all possible argument types (both required and optional).
§Examples
use eventql_parser::prelude::{FunArgs, Type};
// Function with all required parameters: (number, string)
let required = FunArgs::required(vec![Type::Number, Type::String]);
assert_eq!(required.needed, 2);
assert_eq!(required.values.len(), 2);
// Function with optional parameters: (boolean, number?)
let optional = FunArgs {
values: vec![Type::Bool, Type::Number],
needed: 1, // Only first parameter is required
};
assert!(optional.match_arg_count(1)); // Can call with just boolean
assert!(optional.match_arg_count(2)); // Can call with both
assert!(!optional.match_arg_count(3)); // Cannot call with 3 argsFields§
§values: Vec<Type>All argument types, including both required and optional parameters
needed: usizeNumber of required arguments (must be <= values.len())
Implementations§
Source§impl FunArgs
impl FunArgs
Sourcepub fn required(args: Vec<Type>) -> Self
pub fn required(args: Vec<Type>) -> Self
Creates a new FunArgs where all parameters are required.
§Examples
use eventql_parser::prelude::{FunArgs, Type};
let args = FunArgs::required(vec![Type::Number, Type::String]);
assert_eq!(args.needed, 2);
assert_eq!(args.values.len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no argument types defined.
§Examples
use eventql_parser::prelude::{FunArgs, Type};
let empty = FunArgs::required(vec![]);
assert!(empty.is_empty());
let not_empty = FunArgs::required(vec![Type::Number]);
assert!(!not_empty.is_empty());Sourcepub fn match_arg_count(&self, cnt: usize) -> bool
pub fn match_arg_count(&self, cnt: usize) -> bool
Checks if a given argument count is valid for this function signature.
Returns true if the count is between needed (inclusive) and
values.len() (inclusive), meaning all required arguments are
provided and no extra arguments beyond the optional ones are given.
§Examples
use eventql_parser::prelude::{FunArgs, Type};
let args = FunArgs {
values: vec![Type::Bool, Type::Number, Type::String],
needed: 1, // Only first parameter is required
};
assert!(!args.match_arg_count(0)); // Missing required argument
assert!(args.match_arg_count(1)); // Required argument provided
assert!(args.match_arg_count(2)); // Required + one optional
assert!(args.match_arg_count(3)); // All arguments provided
assert!(!args.match_arg_count(4)); // Too many arguments