liveBook · Manning

Duration

As explained in Learn Rust in a Month of Lunches

A duration is an amount or span of time, expressed as an interval or in temporal units.

A `Duration` represents an amount of time. In Rust, it can describe time elapsed between `Instant` values or specify how long a thread should sleep. section 17.2

use std::time::Duration;
use std::thread::sleep;
 
fn main() {
    let three_seconds = Duration::from_secs(3);
    println!("I must sleep now.");
    sleep(three_seconds);
    println!("Did I miss anything?");
}

This example creates a three-second duration and uses it to pause execution. section 17.2

How Learn Rust in a Month of Lunches covers it

How deep it goes
Defines Duration and demonstrates construction from seconds, Instant subtraction, and elapsed-time measurement.
Examples
Shows timing a string-building operation and pausing execution for three seconds.
What you can do after
Apply it via Rust's std::time API to represent elapsed time or specify a sleep interval.
How it connects
Connects Duration to Instant subtraction and elapsed-time measurement, and to thread sleeping.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.