As shown in the following code, I want to encapsulate a timing function that returns the result and the execution time of a closure.
use tap::prelude::Pipe;
use std::time::{Instant, Duration};
pub fn measure_time_with_value<T>(f: impl FnOnce() -> T) -> (T, Duration) {
Instant::now().pipe(|s| (f(), s)).pipe(|(f, s)| (f, s.elapsed()))
}
But I don’t know whether the execution order of the tuple parameters is from left to right, that is, whether it can be simplified to the following code:
pub fn measure_time_with_value<T>(f: impl FnOnce() -> T) -> (T, Duration) {
Instant::now().pipe(|s| (f(), s.elapsed()))
}