MCPcopy Create free account
hub / github.com/aws/clock-bound / try_from

Method try_from

clock-bound/src/daemon/io/phc.rs:131–154  ·  view source on GitHub ↗
(sample: PhcSample)

Source from the content-addressed store, hash-verified

129 type Error = TryFromPhcSampleError;
130
131 fn try_from(sample: PhcSample) -> Result<Self, Self::Error> {
132 if sample.counter_post < sample.counter_pre {
133 return Err(TryFromPhcSampleError::InvalidCounterDiff);
134 }
135 if sample.ptp_clock_error_bound_nsec < 0 {
136 return Err(TryFromPhcSampleError::InvalidClockErrorBound);
137 }
138
139 let builder = event::Phc::builder()
140 .tsc_pre(TscCount::new(sample.counter_pre.into()))
141 .tsc_post(TscCount::new(sample.counter_post.into()))
142 .data(PhcData {
143 time: Instant::from_time(
144 sample.ptp_clock_time.sec.into(),
145 sample.ptp_clock_time.nsec,
146 ),
147 clock_error_bound: Duration::from_nanos(sample.ptp_clock_error_bound_nsec.into()),
148 });
149
150 match builder.build() {
151 Some(phc) => Ok(phc),
152 None => Err(TryFromPhcSampleError::UnexpectedError),
153 }
154 }
155}
156
157/// Contains data used to run PHC runner.

Callers

nothing calls this directly

Calls 5

newFunction · 0.50
dataMethod · 0.45
tsc_postMethod · 0.45
tsc_preMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected