FunArgs

Struct FunArgs 

Source
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 args

Fields§

§values: Vec<Type>

All argument types, including both required and optional parameters

§needed: usize

Number of required arguments (must be <= values.len())

Implementations§

Source§

impl FunArgs

Source

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);
Source

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());
Source

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

Trait Implementations§

Source§

impl Clone for FunArgs

Source§

fn clone(&self) -> FunArgs

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FunArgs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<Type>> for FunArgs

Source§

fn from(value: Vec<Type>) -> Self

Converts to this type from the input type.
Source§

impl Serialize for FunArgs

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.