pub struct StrictFormatter;Expand description
A strict formatter that checks for extra keys and requires all arguments as keyword arguments.
This formatter is based on Python’s string formatting but enforces stricter rules:
- All arguments must be provided as keyword arguments
- All placeholders in the format string must be used
Implementations§
Source§impl StrictFormatter
impl StrictFormatter
Sourcepub fn format(
&self,
format_string: &str,
kwargs: &HashMap<String, String>,
) -> Result<String, FormattingError>
pub fn format( &self, format_string: &str, kwargs: &HashMap<String, String>, ) -> Result<String, FormattingError>
Format a string with keyword arguments.
§Arguments
format_string- The format string with placeholders like{name}.kwargs- The keyword arguments to substitute.
§Returns
The formatted string, or an error if formatting fails.
§Example
use std::collections::HashMap;
use agent_chain_core::utils::formatting::StrictFormatter;
let formatter = StrictFormatter::new();
let mut kwargs = HashMap::new();
kwargs.insert("name".to_string(), "World".to_string());
let result = formatter.format("Hello, {name}!", &kwargs).unwrap();
assert_eq!(result, "Hello, World!");Sourcepub fn validate_input_variables(
&self,
format_string: &str,
input_variables: &[String],
) -> Result<(), FormattingError>
pub fn validate_input_variables( &self, format_string: &str, input_variables: &[String], ) -> Result<(), FormattingError>
Validate that input variables can be used with the format string.
§Arguments
format_string- The format string to validate.input_variables- The input variables that will be provided.
§Returns
Ok(()) if validation passes, or an error if any input variables are not used.
§Example
use agent_chain_core::utils::formatting::StrictFormatter;
let formatter = StrictFormatter::new();
let result = formatter.validate_input_variables("Hello, {name}!", &["name".to_string()]);
assert!(result.is_ok());Trait Implementations§
Source§impl Clone for StrictFormatter
impl Clone for StrictFormatter
Source§fn clone(&self) -> StrictFormatter
fn clone(&self) -> StrictFormatter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StrictFormatter
impl Debug for StrictFormatter
Source§impl Default for StrictFormatter
impl Default for StrictFormatter
Source§fn default() -> StrictFormatter
fn default() -> StrictFormatter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StrictFormatter
impl RefUnwindSafe for StrictFormatter
impl Send for StrictFormatter
impl Sync for StrictFormatter
impl Unpin for StrictFormatter
impl UnwindSafe for StrictFormatter
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
Mutably borrows from an owned value. Read more