Skip to main content

parse_slice

Function parse_slice 

Source
pub fn parse_slice(s: &str) -> Result<u64, SortError>
Expand description

Parse a human-readable slice duration string into seconds.

Supported suffixes: s (seconds), m (minutes), h (hours), d (days). A bare integer is treated as seconds.

§Errors

Returns SortError::InvalidSlice if the string cannot be parsed.

§Examples

use pcap_toolkit::sort::parse_slice;
assert_eq!(parse_slice("1h").unwrap(), 3600);
assert_eq!(parse_slice("30m").unwrap(), 1800);
assert_eq!(parse_slice("1d").unwrap(), 86400);
assert_eq!(parse_slice("120").unwrap(), 120);