autd3_core/datagram/
mod.rsmod gpio;
mod loop_behavior;
mod operation;
mod segment;
mod transition_mode;
mod tuple;
pub use gpio::{GPIOIn, GPIOOut};
pub use loop_behavior::LoopBehavior;
pub use operation::{NullOp, Operation};
pub use segment::Segment;
pub use transition_mode::{TransitionMode, TRANSITION_MODE_NONE};
pub use tuple::{CombinedError, CombinedOperationGenerator};
use std::time::Duration;
use crate::{defined::DEFAULT_TIMEOUT, geometry::Geometry};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DatagramOption {
pub timeout: Duration,
pub parallel_threshold: usize,
}
impl Default for DatagramOption {
fn default() -> Self {
Self {
timeout: DEFAULT_TIMEOUT,
parallel_threshold: usize::MAX,
}
}
}
pub trait DatagramL: std::fmt::Debug {
#[doc(hidden)]
type G;
#[doc(hidden)]
type Error;
#[doc(hidden)]
fn operation_generator_with_loop_behavior(
self,
geometry: &Geometry,
parallel: bool,
segment: Segment,
transition_mode: Option<TransitionMode>,
loop_behavior: LoopBehavior,
) -> Result<Self::G, Self::Error>;
fn option(&self) -> DatagramOption;
}
pub trait DatagramS: std::fmt::Debug {
#[doc(hidden)]
type G;
#[doc(hidden)]
type Error;
#[doc(hidden)]
fn operation_generator_with_segment(
self,
geometry: &Geometry,
parallel: bool,
segment: Segment,
transition_mode: Option<TransitionMode>,
) -> Result<Self::G, Self::Error>;
fn option(&self) -> DatagramOption;
}
impl<D: DatagramL> DatagramS for D {
type G = D::G;
type Error = D::Error;
fn operation_generator_with_segment(
self,
geometry: &Geometry,
parallel: bool,
segment: Segment,
transition_mode: Option<TransitionMode>,
) -> Result<Self::G, Self::Error> {
self.operation_generator_with_loop_behavior(
geometry,
parallel,
segment,
transition_mode,
LoopBehavior::Infinite,
)
}
fn option(&self) -> DatagramOption {
<D as DatagramL>::option(self)
}
}
pub trait Datagram: std::fmt::Debug {
#[doc(hidden)]
type G;
#[doc(hidden)]
type Error;
#[doc(hidden)]
fn operation_generator(
self,
geometry: &Geometry,
parallel: bool,
) -> Result<Self::G, Self::Error>;
fn option(&self) -> DatagramOption {
DatagramOption::default()
}
}
impl<D: DatagramS> Datagram for D {
type G = D::G;
type Error = D::Error;
fn operation_generator(
self,
geometry: &Geometry,
parallel: bool,
) -> Result<Self::G, Self::Error> {
self.operation_generator_with_segment(
geometry,
parallel,
Segment::S0,
Some(TransitionMode::Immediate),
)
}
fn option(&self) -> DatagramOption {
<D as DatagramS>::option(self)
}
}