Type

Enum Type 

Source
pub enum Type {
    Unspecified,
    Number,
    String,
    Bool,
    Array(Box<Type>),
    Record(BTreeMap<String, Type>),
    Subject,
    App {
        args: FunArgs,
        result: Box<Type>,
        aggregate: bool,
    },
    Date,
    Time,
    DateTime,
    Custom(String),
}
Expand description

Type information for expressions.

This enum represents the type of an expression in the E

Variants§

§

Unspecified

Type has not been determined yet

§

Number

Numeric type (f64)

§

String

String type

§

Bool

Boolean type

§

Array(Box<Type>)

Array type

§

Record(BTreeMap<String, Type>)

Record (object) type

§

Subject

Subject pattern type

§

App

Function type with support for optional parameters.

The args field uses FunArgs to support both required and optional parameters. Optional parameters are indicated when args.needed < args.values.len().

§Examples

use eventql_parser::prelude::{Type, FunArgs};

// Function with all required parameters: (number, string) -> boolean
let all_required = Type::App {
    args: vec![Type::Number, Type::String].into(),
    result: Box::new(Type::Bool),
    aggregate: false,
};

// Aggregate function with optional parameter: (boolean?) => number
let with_optional = Type::App {
    args: FunArgs {
        values: vec![Type::Bool],
        needed: 0, // All parameters are optional
    },
    result: Box::new(Type::Number),
    aggregate: true,
};

Fields

§args: FunArgs

Function argument types, supporting optional parameters

§result: Box<Type>

Return type of the function

§aggregate: bool

Whether this is an aggregate function (operates on grouped data)

§

Date

Date type (e.g., 2026-01-03)

Used when a field is explicitly converted to a date using the AS DATE syntax.

§

Time

Time type (e.g., 13:45:39)

Used when a field is explicitly converted to a time using the AS TIME syntax.

§

DateTime

DateTime type (e.g., 2026-01-01T13:45:39Z)

Used when a field is explicitly converted to a datetime using the AS DATETIME syntax.

§

Custom(String)

Custom type not defined in the EventQL reference

Used when a field is converted to a custom type registered in AnalysisOptions::custom_types. The string contains the custom type name as it appears in the query.

§Examples

use eventql_parser::{parse_query, prelude::AnalysisOptions};

let query = parse_query("FROM e IN events PROJECT INTO { ts: e.data.timestamp as CustomTimestamp }").unwrap();
let options = AnalysisOptions::default().add_custom_type("CustomTimestamp");
let typed_query = query.run_static_analysis(&options).unwrap();

Implementations§

Source§

impl Type

Source

pub fn as_record_or_panic_mut(&mut self) -> &mut BTreeMap<String, Type>

Source

pub fn check(self, attrs: &Attrs, other: Type) -> Result<Type, AnalysisError>

Checks if two types are the same.

  • If self is Type::Unspecified then self is updated to the more specific Type.
  • If self is Type::Subject and is checked against a Type::String then self is updated to Type::String

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

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 Type

Source§

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

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

impl Default for Type

Source§

fn default() -> Type

Returns the “default value” for a type. Read more
Source§

impl Display for Type

Provides human-readable string formatting for types.

Function types display optional parameters with a ? suffix. For example, a function with signature (boolean, number?) -> string accepts 1 or 2 arguments. Aggregate functions use => instead of -> in their signature.

§Examples

use eventql_parser::prelude::{Type, FunArgs};

// Basic types
assert_eq!(Type::Number.to_string(), "number");
assert_eq!(Type::String.to_string(), "string");
assert_eq!(Type::Bool.to_string(), "boolean");

// Array type
let arr = Type::Array(Box::new(Type::Number));
assert_eq!(arr.to_string(), "[]number");

// Function with all required parameters
let func = Type::App {
    args: vec![Type::Number, Type::String].into(),
    result: Box::new(Type::Bool),
    aggregate: false,
};
assert_eq!(func.to_string(), "(number, string) -> boolean");

// Function with optional parameters
let func_optional = Type::App {
    args: FunArgs {
        values: vec![Type::Bool, Type::Number],
        needed: 1,
    },
    result: Box::new(Type::String),
    aggregate: false,
};
assert_eq!(func_optional.to_string(), "(boolean, number?) -> string");

// Aggregate function
let agg = Type::App {
    args: vec![Type::Number].into(),
    result: Box::new(Type::Number),
    aggregate: true,
};
assert_eq!(agg.to_string(), "(number) => number");
Source§

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

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

impl Serialize for Type

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§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.