| 191 | // The FromDirective implementation remains the same |
| 192 | impl FromDirective for FormatValidator { |
| 193 | fn from_directive(directive: Directive) -> Result<Self, String> { |
| 194 | // Same implementation as before |
| 195 | match directive.params { |
| 196 | DirectiveParams::KeyValue(params) => { |
| 197 | match params.get("type").and_then(|v| v.as_str()) { |
| 198 | Some(format_type) => match format_type { |
| 199 | "email" | "url" | "uuid" | "ipv4" | "ipv6" | "date" | "datetime" |
| 200 | | "time" | "month" | "week" | "color" => Ok(Self { |
| 201 | format_type: format_type.to_string(), |
| 202 | }), |
| 203 | _ => Err(format!("Unsupported format type: {}", format_type)), |
| 204 | }, |
| 205 | None => Err("@format directive requires a 'type' parameter".into()), |
| 206 | } |
| 207 | } |
| 208 | _ => Err("Invalid params for @format directive".into()), |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | #[cfg(test)] |