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 doesformat: The actual format specification templatearray: 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
impl Format
Sourcepub fn new(instruction: String, format: String, array: Vec<String>) -> Value
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 operationformat- The format specification templatearray- Examples demonstrating the format with different values
§Returns
Value- AValue::Formatvariant 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());Sourcepub fn instruction(&self) -> &str
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");
}Sourcepub fn format(&self) -> &str
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");
}Sourcepub fn array(&self) -> &Vec<String>
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 Display for Format
impl Display for Format
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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
impl ExpressionLike for Format
Source§fn evaluate(&self, _context: &mut dyn ContextLike) -> Result<Value>
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)
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
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
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('"'));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> 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<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.