Literal

Enum Literal 

Source
pub enum Literal {
    Empty,
    Bool(bool),
    Date(DateTime),
    Number(f64),
    Task(Option<bool>, Arc<str>),
    Text(Arc<str>),
}
Expand description

Literal values supported by AIMX expressions.

Provides the core literal variants and helpers used by the expression engine for parsing, type checking, comparison, and conversion.

Variants§

§

Empty

Empty or untyped literal.

§

Bool(bool)

Boolean value.

§

Date(DateTime)

Date/time value.

§

Number(f64)

64-bit floating point number.

§

Task(Option<bool>, Arc<str>)

Task with optional status and description. Status semantics: Some(true)=completed, Some(false)=failed, None=pending.

§

Text(Arc<str>)

UTF-8 string value.

Implementations§

Source§

impl Literal

Source

pub fn is_type(&self, typedef: &Typedef) -> bool

Check if this literal matches the specified type.

§Arguments
  • typedef - The type definition to check against
§Returns

Returns true if this literal matches the specified type, false otherwise.

Source

pub fn get_type(&self) -> Result<Typedef>

Get the type of this literal.

§Returns

Returns a Result<Typedef> containing the type of this literal, or an error if this is an Empty literal.

Source

pub fn as_type(self, literal: &Literal) -> Result<Literal>

Convert this literal to match the type of another literal.

This method performs type conversion according to the grammar’s type promotion rules, converting this literal to match the type of the provided reference literal.

§Arguments
  • literal - The reference literal whose type determines the conversion
§Returns

Returns a Result<Literal> containing the converted literal or an error if conversion is not possible.

Source

pub fn to_type(self, typedef: &Typedef) -> Result<Literal>

Source

pub fn is_empty(&self) -> bool

Check if this literal is empty.

Source

pub fn is_bool(&self) -> bool

Check if this literal represents a boolean value.

Source

pub fn from_bool(b: bool) -> Self

Create a boolean literal from a boolean value.

Source

pub fn as_bool(self) -> Literal

Convert this literal to a boolean representation.

Performs type conversion to boolean according to the grammar’s truthiness rules:

  • Numbers: 0 is false, non-zero is true
  • Text: Empty string is false, non-empty is true
  • Dates: Always true (they exist)
  • Tasks: Status determines value, no status is false

This function provides an implicit error free conversion from any literal to bool specifically for the conditional ternary operator making a type safe error free check possible.

e.g. user.birthday ? user.birthday : _

Source

pub fn to_bool(&self) -> bool

Extract a boolean value from this literal.

This is a convenience method for when you specifically need a bool value.

Source

pub fn is_date(&self) -> bool

Check if this literal represents a date value.

Source

pub fn from_date(d: DateTime) -> Self

Create a date literal from a DateTime value.

Source

pub fn as_date(self) -> Result<Literal>

Convert this literal to a date representation.

Attempts to convert the literal to a date according to the grammar’s conversion rules:

  • Boolean: true becomes Unix epoch + 1 second, false becomes Unix epoch
  • Number: Interpreted as Unix timestamp
  • Text: Parsed as date if possible
  • Task: Text component parsed as date if possible
Source

pub fn is_number(&self) -> bool

Check if this literal represents a number value.

Source

pub fn from_number(n: f64) -> Self

Create a number literal from an f64 value.

Source

pub fn as_number(self) -> Result<Literal>

Convert this literal to a number representation.

Attempts to convert the literal to a number according to the grammar’s conversion rules:

  • Boolean: false becomes 0, true becomes 1
  • Date: Converted to Unix timestamp
  • Text: Parsed as number if it represents a valid numeric literal
  • Task: Status determines value (true=1, false=-1, none=0)
Source

pub fn to_number(&self) -> Result<f64>

Extract a numeric value from this literal.

This is a convenience method for when you specifically need a f64 number.

Source

pub fn is_task(&self) -> bool

Check if this literal represents a task value.

Source

pub fn from_task(status: Option<bool>, task: Arc<str>) -> Self

Create a task literal from status and text.

Source

pub fn as_task(self) -> Result<Literal>

Convert this literal to a task representation.

Converts the literal to a task according to the grammar’s conversion rules:

  • Boolean: Status becomes the boolean value, text becomes “true”/“false”
  • Date: No status, text becomes date string
  • Number: Status based on sign (positive=true, negative=false, zero=none), text becomes number string
  • Text: No status, text remains the same
Source

pub fn is_text(&self) -> bool

Check if this literal represents a text value.

Source

pub fn from_text(text: Arc<str>) -> Self

Create a text literal from a String.

Source

pub fn as_text(self) -> Result<Literal>

Convert this literal to a text representation.

Converts the literal to text according to the grammar’s conversion rules:

  • Boolean: “true” or “false”
  • Date: Formatted as date string
  • Number: Formatted as string
  • Task: Text component of the task
Source

pub fn type_as_string(&self) -> &'static str

Get a string representation of this literal’s type.

Source

pub fn print(&self, writer: &mut Writer)

Source

pub fn to_formula(&self) -> String

Return the formula-string representation (round-trippable by the parser).

Trait Implementations§

Source§

impl Clone for Literal

Source§

fn clone(&self) -> Literal

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 Literal

Source§

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

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

impl Display for Literal

Source§

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

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

impl Ord for Literal

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Literal

Source§

fn eq(&self, other: &Literal) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Literal

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl WriterLike for Literal

Source§

fn write(&self, writer: &mut Writer)

Serialize this expression with the given Writer.
Source§

fn to_stringized(&self) -> String

Return a string representation (raw unsafe output).
Source§

fn to_sanitized(&self) -> String

Return a sanitized string representation (escaped for safe output).
Source§

fn to_expressionized(&self) -> String

Return a sanitized string representation (escaped for safe output).
Source§

impl Eq for Literal

Source§

impl StructuralPartialEq for Literal

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,