MCPcopy Create free account
hub / github.com/biblius/validify / parse_ip_full

Function parse_ip_full

validify_derive/src/validate/parser.rs:364–389  ·  view source on GitHub ↗
(meta: &ParseNestedMeta)

Source from the content-addressed store, hash-verified

362}
363
364pub fn parse_ip_full(meta: &ParseNestedMeta) -> Result<Ip, syn::Error> {
365 let mut validation = Ip::default();
366
367 meta.parse_nested_meta(|meta| {
368 if meta.path.is_ident("format") {
369 let content = meta.value()?;
370 match content.parse::<syn::LitStr>() {
371 Ok(format) => match format.value().as_str() {
372 "v4" => validation.format = Some(super::validation::IpFormat::V4),
373 "v6" => validation.format = Some(super::validation::IpFormat::V6),
374 _ => abort!(format.span(), "Invalid IP format, accepted are: v4, v6"),
375 },
376 Err(_) => {
377 return Err(meta.error("ip format must be a string literal: \"v4\"/\"v6\""))
378 }
379 }
380 return Ok(());
381 }
382
383 code_and_message!(validation, meta);
384
385 Err(meta.error("Unrecognized ip parameter, accepted are: format, code, message"))
386 })?;
387
388 Ok(validation)
389}
390
391pub fn parse_time(meta: &ParseNestedMeta) -> Result<Time, syn::Error> {
392 const INTERVALS: [&str; 5] = ["seconds", "minutes", "hours", "days", "weeks"];

Callers 1

parse_single_validationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected