You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: from_string.rs
    path of file: ./repos/ockam/implementations/rust/ockam/ockam_core/src/env
    
    the code of the file until where you have to start completion: use crate::env::error;
use crate::errcode::{Kind, Origin};
use crate::{Error, Result};
use once_cell::sync::OnceCell;
use regex::Regex;
use std::path::PathBuf;
use std::time::Duration;

/// For-internal-use trait for types that can be parsed from string
pub trait FromString: Sized {
    /// Parses string and gives the result. Can return an error in case
    /
    
pub fn parse_duration(arg: &str) -> Result<Duration> {
    let needles = DURATION_REGEX
        .get_or_init(|| {
            Regex::new(r"(?P<numeric_duration>[0-9]+)(?P<length_sigil>d|h|m|s|ms)?$").unwrap()
        })
        .captures(arg)
        .ok_or(Error::new(
            Origin::Api,
            Kind::Serialization,
            "Invalid duration.",
        ))?;
    let time = needles["numeric_duration"]
        .parse::<u64>()
        .map_err(|_| Error::new(Origin::Api, Kind::Serialization, "Invalid duration."))?;

    match needles.name("length_sigil") {
        Some(n) => match n.as_str() {
            "ms" => Ok(Duration::from_millis(time)),
            "s" => Ok(Duration::from_secs(time)),
            "m" => Ok(Duration::from_secs(60 * time)),
            "h" => Ok(Duration::from_secs(60 * 60 * time)),
            "d" => Ok(Duration::from_secs(60 * 60 * 24 * time)),
            _ => unreachable!("Alternatives excluded by regex."),
        },
        None => Ok(Duration::from_secs(time)),
    }
}