1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::time::Duration;

use crate::{datagram::*, error::AUTDInternalError};

/// Datagram to synchronize devices
#[derive(Default)]
pub struct Synchronize {}

impl Synchronize {
    pub const fn new() -> Self {
        Self {}
    }
}

impl Datagram for Synchronize {
    type O1 = crate::operation::SyncOp;
    type O2 = crate::operation::NullOp;

    fn operation(self) -> Result<(Self::O1, Self::O2), AUTDInternalError> {
        Ok((Default::default(), Default::default()))
    }

    fn timeout(&self) -> Option<Duration> {
        Some(Duration::from_millis(200))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_sync_timeout() {
        let stop = Synchronize::new();
        let timeout = <Synchronize as Datagram>::timeout(&stop);
        assert!(timeout.is_some());
        assert!(timeout.unwrap() > Duration::ZERO);
    }

    #[test]
    fn test_sync_operation() {
        let stop = Synchronize::default();
        let r = <Synchronize as Datagram>::operation(stop);
        assert!(r.is_ok());
        let _: (crate::operation::SyncOp, crate::operation::NullOp) = r.unwrap();
    }
}