1 2 3 4 5 6 7 8 9 10 11 12
use std::io::Result; use std::time::{Duration, Instant}; pub trait Pinger { fn ping(&self) -> Result<()>; } pub fn timed<P: Pinger + ?Sized>(pinger: &P) -> Result<Duration> { let start = Instant::now(); pinger.ping()?; Ok(start.elapsed()) }