fn duration(start: Instant, end: Instant, duration_type: &str) -> Result<String, String> {
    match duration_type {
        // Nanoseconds
        "ns" => Ok(end.duration_since(start).as_nanos().to_string()),
        // Milliseconds
        "ms" => Ok(end.duration_since(start).as_millis().to_string()),
        // Seconds
        "s" => Ok(end.duration_since(start).as_secs().to_string()),
        // Not supported
        _ => Err(format!("{} is not a valid duration type", duration_type)),
    }
}
/// Returns the duration between two instants. The unit is specified by the parameter `duration_type`.
Returns the duration between two instants. The unit is specified by the parameter `duration_type`.
Returns the duration between two instants . The unit is specified by the parameter ` duration_type ` .
fn duration(start: Instant, end: Instant, duration_type: &str) -> Result<String, String> {
    match duration_type {
        // Nanoseconds
        "ns" => Ok(end.duration_since(start).as_nanos().to_string()),
        // Milliseconds
        "ms" => Ok(end.duration_since(start).as_millis().to_string()),
        // Seconds
        "s" => Ok(end.duration_since(start).as_secs().to_string()),
        // Not supported
        _ => Err(format!("{} is not a valid duration type", duration_type)),
    }
}
fn duration ( start : Instant , end : Instant , duration_type : & str ) -> Result < String , String > { match duration_type { // Nanoseconds " " => Ok ( end . duration_since ( start ) . as_nanos ( ) . to_string ( ) ) , // Milliseconds " " => Ok ( end . duration_since ( start ) . as_millis ( ) . to_string ( ) ) , // Seconds " " => Ok ( end . duration_since ( start ) . as_secs ( ) . to_string ( ) ) , // Not supported _ => Err ( format ! ( " " duration_type ) ) , } }
Returns the duration between two instants.
Returns the duration between two instants .
start
Instant
end
Instant
duration_type
&str
start
Instant
end
Instant
duration_type
&str