use snafu::{OptionExt as _, ResultExt as _, Snafu}; use std::num::ParseIntError; pub type Microsecond = u32; #[derive(Debug, Snafu)] pub enum TakeError { /// microseconds are supposed to be followed by - Malformed, /// could not parse the microsecond as an integer ParseIntegerError { source: ParseIntError }, } pub fn take(path: &str) -> Result<(Microsecond, &str), TakeError> { let (microsecond, rest) = path.split_once('-').context(MalformedSnafu)?; let microsecond = microsecond.parse().context(ParseIntegerSnafu)?; Ok((microsecond, rest)) }