Macro sql::normalize::with_options[][src]

macro_rules! with_options {
    (struct $name : ident { $($field_name : ident : $field_type : ident,) * }) => { ... };
}
Expand description

This macro accepts a struct definition and will generate it and a try_from method that takes a Vec<WithOption> which will extract and type check options based on the struct field names and types.

The macro wraps all field types in an Option in the generated struct. The TryFrom implementation sets fields to None if they are not present in the provided WITH options.

Field names must match exactly the lowercased option name. Supported types are:

  • String: expects a SQL string (WITH (name = "value")) or identifier (WITH (name = text)).
  • bool: expects either a SQL bool (WITH (name = true)) or a valueless option which will be interpreted as true: (WITH (name).
  • Interval: expects either a SQL interval or string that can be parsed as an interval.