Struct Format

Source
pub struct Format { /* private fields */ }
Expand description

Represents a formatting instruction value in the AIMX expression language.

Format values provide a way to specify how values should be formatted when displayed or serialized. They follow the pattern: "Instruction" <format> "Example1", "Example2", ...

§Structure

A Format contains three components:

  • instruction: Human-readable description of what the format does
  • format: The actual format specification template
  • array: Examples demonstrating the format with different values

§Examples

use aimx::values::Format;
use aimx::Value;
 
let currency_format = Format::new(
    "Display as currency".to_string(),
    "$0.00".to_string(),
    vec!["$42.00".to_string(), "$123.45".to_string()]
);
 
// Extract the Format struct from the Value enum
if let Value::Format(ref format) = currency_format {
    assert_eq!(format.instruction(), "Display as currency");
    assert_eq!(format.format(), "$0.00");
    assert_eq!(format.array().len(), 2);
} else {
    panic!("Expected Value::Format");
}

See also: parse_format, crate::typedef::Typedef::Format, crate::value::Value::Format

Implementations§

Source§

impl Format

Source

pub fn new(instruction: String, format: String, array: Vec<String>) -> Value

Creates a new Format value wrapped in a Value enum.

This constructor creates a new Format instance and returns it wrapped as a Value::Format variant. This is the primary way to create format values for use in the expression evaluation system.

§Arguments
  • instruction - Human-readable description of the formatting operation
  • format - The format specification template
  • array - Examples demonstrating the format with different values
§Returns
  • Value - A Value::Format variant containing the new format
§Examples
use aimx::{Value, values::Format};
 
let format_value = Format::new(
    "Display as percentage".to_string(),
    "0.0%".to_string(),
    vec!["42.5%".to_string(), "99.9%".to_string()]
);
 
assert!(format_value.is_format());
Source

pub fn instruction(&self) -> &str

Returns a reference to the instruction text.

The instruction provides a human-readable description of what the formatting operation does, such as “Display as currency” or “Format as date”.

§Returns
  • &str - A reference to the instruction string
§Examples
use aimx::values::Format;
use aimx::Value;
 
let format_value = Format::new(
    "Format as currency".to_string(),
    "$0.00".to_string(),
    vec![]
);
assert!(format_value.is_format());
 
// Extract the Format struct from the Value enum
if let Value::Format(ref format) = format_value {
    assert_eq!(format.instruction(), "Format as currency");
} else {
    panic!("Expected Value::Format");
}
Source

pub fn format(&self) -> &str

Returns a reference to the format specification.

The format specification is the actual template that defines how values should be formatted, such as “$0.00” for currency or “MM/DD/YYYY” for dates.

§Returns
  • &str - A reference to the format specification string
§Examples
use aimx::values::Format;
use aimx::Value;
 
let format_value = Format::new(
    "Display as currency".to_string(),
    "$0.00".to_string(),
    vec![]
);
assert!(format_value.is_format());
 
// Extract the Format struct from the Value enum
if let Value::Format(ref format) = format_value {
    assert_eq!(format.format(), "$0.00");
} else {
    panic!("Expected Value::Format");
}
Source

pub fn array(&self) -> &Vec<String>

Returns a reference to the array of example values.

The examples demonstrate how the format works with different values, providing concrete examples of the expected output.

§Returns
  • &Vec<String> - A reference to the vector of example strings
§Examples
use aimx::values::Format;
use aimx::Value;
 
let format_value = Format::new(
    "Display numbers".to_string(),
    "0.00".to_string(),
    vec!["42.00".to_string(), "123.45".to_string()]
);
assert!(format_value.is_format());
 
// Extract the Format struct from the Value enum
if let Value::Format(ref format) = format_value {
    let examples = format.array();
    assert_eq!(examples.len(), 2);
    assert_eq!(examples[0], "42.00");
    assert_eq!(examples[1], "123.45");
} else {
    panic!("Expected Value::Format");
}

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Format

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 Format

Source§

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

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

impl Display for Format

Source§

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

Formats the format value for human-readable display.

This implementation uses the stringizer writer mode to produce a clean, human-readable representation of the format value.

§Arguments
  • f - The formatter to write to
§Returns
  • fmt::Result - The result of the formatting operation
§Examples
use aimx::values::Format;
 
let format = Format::new(
    "Display as currency".to_string(),
    "$0.00".to_string(),
    vec!["$42.00".to_string()]
);
 
let display_string = format.to_string();
assert!(display_string.contains("Display as currency"));
assert!(display_string.contains("$0.00"));
Source§

impl ExpressionLike for Format

Source§

fn evaluate(&self, _context: &mut dyn ContextLike) -> Result<Value>

Evaluates the format value, returning itself unchanged.

Format values are constant and evaluate to themselves. This method implements the required evaluation behavior for the ExpressionLike trait.

§Arguments
  • _context - The evaluation context (unused for format values)
§Returns
  • Result<Value> - The format value itself wrapped in a result
§Examples
use aimx::{ExpressionLike, Context, values::Format};
 
let format = Format::new(
    "Display as percentage".to_string(),
    "0.0%".to_string(),
    vec!["42.5%".to_string()]
);
 
let mut context = Context::new();
let result = format.evaluate(&mut context).unwrap();
 
assert!(result.is_format());
Source§

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

Writes the format value to a writer using the appropriate formatting mode.

This method delegates to the writer’s print_format method, which handles the different output modes (raw, escaped, quoted).

§Arguments
  • writer - The writer to write the formatted output to
§Examples
use aimx::{ExpressionLike, Writer, PrintMode, Prefix, values::Format, Value};
 
let format_value = Format::new(
    "Display as currency".to_string(),
    "$0.00".to_string(),
    vec!["$42.00".to_string()]
);
assert!(format_value.is_format());
 
// Extract the Format struct from the Value enum
if let Value::Format(ref format) = format_value {
    let mut writer = Writer::new(PrintMode::None, Prefix::None);
    format.write(&mut writer);
    let output = writer.finish();
 
    assert!(output.contains("Display as currency"));
    assert!(output.contains("$0.00"));
    assert!(output.contains("$42.00"));
} else {
    panic!("Expected Value::Format");
}
Source§

fn to_sanitized(&self) -> String

Converts the format value to a sanitized string representation.

This method produces a string with special characters escaped, making it safe for contexts like JSON serialization or logging.

§Returns
  • String - A sanitized string representation of the format
§Examples
use aimx::{ExpressionLike, values::Format};
 
let format = Format::new(
    "Format with quotes\"".to_string(),
    "<template>".to_string(),
    vec!["example\"quoted".to_string()]
);
 
let sanitized = format.to_sanitized();
// Special characters like quotes will be escaped
assert!(sanitized.contains("\\\""));
Source§

fn to_formula(&self) -> String

Converts the format value to a formula string representation.

This method produces a string with proper quoting and escaping for use in formulas, making it round-trippable through parsing.

§Returns
  • String - A formula string representation of the format
§Examples
use aimx::{ExpressionLike, values::Format};
 
let format = Format::new(
    "Display as percentage".to_string(),
    "0.0%".to_string(),
    vec!["42.5%".to_string()]
);
 
let formula = format.to_formula();
// Values will be properly quoted for formula context
assert!(formula.contains('"'));
Source§

impl PartialEq for Format

Source§

fn eq(&self, other: &Format) -> 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 StructuralPartialEq for Format

Auto Trait Implementations§

§

impl Freeze for Format

§

impl RefUnwindSafe for Format

§

impl Send for Format

§

impl Sync for Format

§

impl Unpin for Format

§

impl UnwindSafe for Format

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.

§

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,