(meta: &ParseNestedMeta)
| 259 | } |
| 260 | |
| 261 | pub fn parse_custom_full(meta: &ParseNestedMeta) -> Result<Custom, syn::Error> { |
| 262 | let mut validation = Custom { |
| 263 | path: syn::Path { |
| 264 | leading_colon: None, |
| 265 | segments: Punctuated::new(), |
| 266 | }, |
| 267 | code: None, |
| 268 | message: None, |
| 269 | }; |
| 270 | |
| 271 | meta.parse_nested_meta(|meta| { |
| 272 | if meta.path.is_ident("function") { |
| 273 | let content = meta.value()?; |
| 274 | match content.parse::<syn::Path>() { |
| 275 | Ok(path) => { |
| 276 | validation.path = path; |
| 277 | } |
| 278 | Err(_) => return Err(meta.error( |
| 279 | "custom value must be a path to a function that takes in the type of the field", |
| 280 | )), |
| 281 | } |
| 282 | return Ok(()); |
| 283 | } |
| 284 | |
| 285 | code_and_message!(validation, meta); |
| 286 | |
| 287 | Err(meta.error("Unrecognized custom parameter, accepted are: path, code, message")) |
| 288 | })?; |
| 289 | |
| 290 | if validation.path.segments.is_empty() { |
| 291 | abort!(meta.input.span(), "custom validation must contain a path") |
| 292 | } |
| 293 | |
| 294 | Ok(validation) |
| 295 | } |
| 296 | |
| 297 | pub fn parse_regex_full(meta: &ParseNestedMeta) -> Result<Regex, syn::Error> { |
| 298 | let mut validation = Regex { |
no test coverage detected