Hermes
A very convenient string parsing crate that can parse function and variable references in strings into corresponding values.
String Syntax Example
let input = "${hostname()}+\"dd\"+true+${name}+${invalid}+${random_str(${len})}+${multiply(1,-2.5,3)}";
The string can contain function calls, variable references, booleans, numbers, and strings, connected by "+".
Function Expression: syntax is${function_name(args...)}, where function_name is the name of a function, and args are multiple parameters, which can also be absent, depending on the parameters required by the function. Args can also be function calls, variable references, booleans, numbers, and strings.Variable Expression: syntax is${variable_name}.Boolean Expression: justtrueorfalse.Number Expression: like10,-12,12.56and so on.String Expression: any characters between two double quotation marks. like"foo and bar".
How to use
You need to initialize a Cache struct to store all your variables and functions. Then, you can call parse or parse_to_string function to parse the a string.
See example below:
use ;
Output:
Inner Function
random_str(len)Get a random string with length.random_bool()Get a random boolean value.random_num()orrandom_num(end)orrandom_num(start,end)Get a random number.hostname()Get your hostname.current_timeGet current time with format.