autd3_core/datagram/
mod.rs1mod gpio;
2mod loop_behavior;
3mod operation;
4mod segment;
5mod transition_mode;
6mod tuple;
7
8pub use gpio::{GPIOIn, GPIOOut};
9pub use loop_behavior::LoopBehavior;
10pub use operation::{NullOp, Operation};
11pub use segment::Segment;
12pub use transition_mode::{TRANSITION_MODE_NONE, TransitionMode};
13pub use tuple::{CombinedError, CombinedOperationGenerator};
14
15use std::time::Duration;
16
17use crate::{defined::DEFAULT_TIMEOUT, geometry::Geometry};
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub struct DatagramOption {
22 pub timeout: Duration,
24 pub parallel_threshold: usize,
26}
27
28impl Default for DatagramOption {
29 fn default() -> Self {
30 Self {
31 timeout: DEFAULT_TIMEOUT,
32 parallel_threshold: usize::MAX,
33 }
34 }
35}
36
37pub trait DatagramL: std::fmt::Debug {
39 #[doc(hidden)]
40 type G;
41 #[doc(hidden)]
42 type Error;
43
44 #[doc(hidden)]
45 fn operation_generator_with_loop_behavior(
46 self,
47 geometry: &Geometry,
48 parallel: bool,
49 segment: Segment,
50 transition_mode: Option<TransitionMode>,
51 loop_behavior: LoopBehavior,
52 ) -> Result<Self::G, Self::Error>;
53
54 #[must_use]
56 fn option(&self) -> DatagramOption;
57}
58
59pub trait DatagramS: std::fmt::Debug {
61 #[doc(hidden)]
62 type G;
63 #[doc(hidden)]
64 type Error;
65
66 #[doc(hidden)]
67 fn operation_generator_with_segment(
68 self,
69 geometry: &Geometry,
70 parallel: bool,
71 segment: Segment,
72 transition_mode: Option<TransitionMode>,
73 ) -> Result<Self::G, Self::Error>;
74
75 #[must_use]
77 fn option(&self) -> DatagramOption;
78}
79
80impl<D: DatagramL> DatagramS for D {
81 type G = D::G;
82 type Error = D::Error;
83
84 fn operation_generator_with_segment(
85 self,
86 geometry: &Geometry,
87 parallel: bool,
88 segment: Segment,
89 transition_mode: Option<TransitionMode>,
90 ) -> Result<Self::G, Self::Error> {
91 self.operation_generator_with_loop_behavior(
92 geometry,
93 parallel,
94 segment,
95 transition_mode,
96 LoopBehavior::Infinite,
97 )
98 }
99
100 fn option(&self) -> DatagramOption {
101 <D as DatagramL>::option(self)
102 }
103}
104
105pub trait Datagram: std::fmt::Debug {
107 #[doc(hidden)]
108 type G;
109 #[doc(hidden)]
110 type Error;
111
112 #[doc(hidden)]
113 fn operation_generator(
114 self,
115 geometry: &Geometry,
116 parallel: bool,
117 ) -> Result<Self::G, Self::Error>;
118
119 #[must_use]
121 fn option(&self) -> DatagramOption {
122 DatagramOption::default()
123 }
124}
125
126impl<D: DatagramS> Datagram for D {
127 type G = D::G;
128 type Error = D::Error;
129
130 fn operation_generator(
131 self,
132 geometry: &Geometry,
133 parallel: bool,
134 ) -> Result<Self::G, Self::Error> {
135 self.operation_generator_with_segment(
136 geometry,
137 parallel,
138 Segment::S0,
139 Some(TransitionMode::Immediate),
140 )
141 }
142
143 fn option(&self) -> DatagramOption {
144 <D as DatagramS>::option(self)
145 }
146}