Skip to content

Stabilize Duration::span as-is? #1243

Closed
@SimonSapin

Description

@SimonSapin

std::time currently contains:

impl Duration {
    /// Runs a closure, returning the duration of time it took to run the
    /// closure.
    #[unstable(feature = "duration_span",
               reason = "unsure if this is the right API or whether it should \
                         wait for a more general \"moment in time\" \
                         abstraction")]
    pub fn span<F>(f: F) -> Duration where F: FnOnce() {
        let start = SteadyTime::now();
        f();
        &SteadyTime::now() - &start
    }
}

I’d like to stabilize this method unchanged. Even if a "moment in time" abstraction exists, doing the let start = now(); do stuff; now() - start dance gets tedious very quickly and a closure-based Duration::span method would still be valuable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions