Skip to content

Commit 1ee6c5d

Browse files
teodlydavidv1992
authored andcommitted
simplified cloning
1 parent f461188 commit 1ee6c5d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

statime-linux/src/main.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ use tokio::{
3838
time::Sleep,
3939
};
4040

41-
trait PortClock: Clock<Error = <LinuxClock as Clock>::Error> + PortTimestampToTime {}
42-
impl PortClock for LinuxClock {}
43-
impl PortClock for SharedClock<OverlayClock<LinuxClock>> {}
44-
type BoxedClock = Box<dyn PortClock + Send + Sync>;
41+
trait PortClock: Clock<Error = <LinuxClock as Clock>::Error> + PortTimestampToTime + Send + Sync {
42+
fn clone_box(&self) -> Box<dyn PortClock>;
43+
}
44+
impl PortClock for LinuxClock {
45+
fn clone_box(&self) -> Box<dyn PortClock> {
46+
Box::new(self.clone())
47+
}
48+
}
49+
impl PortClock for SharedClock<OverlayClock<LinuxClock>> {
50+
fn clone_box(&self) -> Box<dyn PortClock> {
51+
Box::new(self.clone())
52+
}
53+
}
54+
type BoxedClock = Box<dyn PortClock>;
4555
type SharedOverlayClock = SharedClock<OverlayClock<LinuxClock>>;
4656

4757
#[derive(Parser, Debug)]
@@ -305,7 +315,7 @@ async fn actual_main() {
305315
for port_config in config.ports {
306316
let interface = port_config.interface;
307317
let network_mode = port_config.network_mode;
308-
let (port_clock, port_clock2, timestamping) = match port_config.hardware_clock {
318+
let (port_clock, timestamping) = match port_config.hardware_clock {
309319
Some(idx) => {
310320
let mut clock = LinuxClock::open_idx(idx).expect("Unable to open clock");
311321
if let Some(id) = clock_name_map.get(&idx) {
@@ -319,15 +329,13 @@ async fn actual_main() {
319329
.push(start_clock_task(clock.clone(), system_clock.clone()));
320330
}
321331
(
322-
Box::new(clock.clone()) as BoxedClock,
323332
Box::new(clock) as BoxedClock,
324333
InterfaceTimestampMode::HardwarePTPAll,
325334
)
326335
}
327336
None => {
328337
clock_port_map.push(None);
329338
(
330-
system_clock.clone_boxed(),
331339
system_clock.clone_boxed(),
332340
InterfaceTimestampMode::SoftwareAll,
333341
)
@@ -339,7 +347,7 @@ async fn actual_main() {
339347
let port = instance.add_port(
340348
port_config.into(),
341349
KalmanConfiguration::default(),
342-
port_clock2,
350+
port_clock.clone_box(),
343351
rng,
344352
);
345353

0 commit comments

Comments
 (0)