INNER CODE UNIT · Rust

validate_duration

sachaos/viddy · src/cli.rs:129

fn validate_duration(s: &str) -> Result<Duration> {
    let d = parse_duration_from_str(s)?;
    if d < Duration::milliseconds(100) {
        bail!("The short interval is not allowed (less than 100ms)");
    }

    Ok(d)
}

fn parse_duration_from_str(s: &str) -> Result<Duration> {
    match humantime::parse_duration(s) {
        Ok(d) => Ok(Duration::from_std(d)?),
        Err(_) => {
            // If the input is only a number, we assume it's in seconds
            let n = s.parse::<f64>()?;
            Ok(Duration::milliseconds((n * 1000.0) as i64))
        }
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…