Function parse_ttl
pub fn parse_ttl(ttl_str: &str) -> Result<u32, ParseError>Expand description
parses the string following the rules from: https://tools.ietf.org/html/rfc2308 (NXCaching RFC) and https://www.zytrax.com/books/dns/apa/time.html
default is seconds #s = seconds = # x 1 seconds (really!) #m = minutes = # x 60 seconds #h = hours = # x 3600 seconds #d = day = # x 86400 seconds #w = week = # x 604800 seconds
returns the result of the parsing or and error
ยงExample
use hickory_proto::serialize::txt::parse_ttl;
assert_eq!(parse_ttl("0").unwrap(), 0);
assert!(parse_ttl("s").is_err());
assert!(parse_ttl("").is_err());
assert_eq!(parse_ttl("0s").unwrap(), 0);
assert_eq!(parse_ttl("1").unwrap(), 1);
assert_eq!(parse_ttl("1S").unwrap(), 1);
assert_eq!(parse_ttl("1s").unwrap(), 1);
assert_eq!(parse_ttl("1M").unwrap(), 60);
assert_eq!(parse_ttl("1m").unwrap(), 60);
assert_eq!(parse_ttl("1H").unwrap(), 3600);
assert_eq!(parse_ttl("1h").unwrap(), 3600);
assert_eq!(parse_ttl("1D").unwrap(), 86400);
assert_eq!(parse_ttl("1d").unwrap(), 86400);
assert_eq!(parse_ttl("1W").unwrap(), 604800);
assert_eq!(parse_ttl("1w").unwrap(), 604800);
assert_eq!(parse_ttl("1s2d3w4h2m").unwrap(), 1+2*86400+3*604800+4*3600+2*60);
assert_eq!(parse_ttl("3w3w").unwrap(), 3*604800+3*604800);
assert!(parse_ttl("7102w").is_err());