Extension trait for Clock that provides offset and RTT measurement functionality
| 62 | } |
| 63 | |
| 64 | /// Extension trait for Clock that provides offset and RTT measurement functionality |
| 65 | pub trait ClockExt<T: NanoType + Copy>: Clock<T> { |
| 66 | /// Get the offset and RTT measurement for this reading between this clock and another clock. |
| 67 | /// The "offset" is from the caller to the `other` clock - e.g. if `self` is running behind `other`, |
| 68 | /// we would expect a negative value, and if it `self` running ahead of `other`, we expect a positive value. |
| 69 | fn get_offset_and_rtt(&self, other: &impl Clock<T>) -> ClockOffsetAndRtt<T> { |
| 70 | let our_read1 = self.get_time(); |
| 71 | let their_read = other.get_time(); |
| 72 | let our_read2 = self.get_time(); |
| 73 | let mid = our_read1.midpoint(our_read2); |
| 74 | let offset = mid - their_read; |
| 75 | let rtt = our_read2 - our_read1; |
| 76 | ClockOffsetAndRtt::new(offset, rtt) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /// Blanket implementation of `ClockExt` for all types that implement Clock |
no outgoing calls
no test coverage detected