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
impl Literal
Sourcepub fn get_type(&self) -> Result<Typedef>
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.
Sourcepub fn as_type(self, literal: &Literal) -> Result<Literal>
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.
pub fn to_type(self, typedef: &Typedef) -> Result<Literal>
Sourcepub fn as_bool(self) -> Literal
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 : _
Sourcepub fn to_bool(&self) -> bool
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.
Sourcepub fn as_date(self) -> Result<Literal>
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
Sourcepub fn from_number(n: f64) -> Self
pub fn from_number(n: f64) -> Self
Create a number literal from an f64 value.
Sourcepub fn as_number(self) -> Result<Literal>
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)
Sourcepub fn to_number(&self) -> Result<f64>
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.
Sourcepub fn from_task(status: Option<bool>, task: Arc<str>) -> Self
pub fn from_task(status: Option<bool>, task: Arc<str>) -> Self
Create a task literal from status and text.
Sourcepub fn as_task(self) -> Result<Literal>
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
Sourcepub fn as_text(self) -> Result<Literal>
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
Sourcepub fn type_as_string(&self) -> &'static str
pub fn type_as_string(&self) -> &'static str
Get a string representation of this literal’s type.
pub fn print(&self, writer: &mut Writer)
Sourcepub fn to_formula(&self) -> String
pub fn to_formula(&self) -> String
Return the formula-string representation (round-trippable by the parser).
Trait Implementations§
Source§impl Ord for Literal
impl Ord for Literal
Source§impl PartialOrd for Literal
impl PartialOrd for Literal
Source§impl WriterLike for Literal
impl WriterLike for Literal
Source§fn to_stringized(&self) -> String
fn to_stringized(&self) -> String
Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Source§fn to_expressionized(&self) -> String
fn to_expressionized(&self) -> String
impl Eq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.