autd3_core/modulation/
error.rs

1use core::convert::Infallible;
2
3use crate::firmware::SamplingConfigError;
4
5#[derive(Debug, PartialEq, Clone)]
6/// An error occurred during modulation calculation.
7pub struct ModulationError {
8    msg: String,
9}
10
11// GRCOV_EXCL_START
12impl core::fmt::Display for ModulationError {
13    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14        write!(f, "{}", self.msg)
15    }
16}
17
18impl core::error::Error for ModulationError {}
19
20impl ModulationError {
21    /// Creates a new [`ModulationError`].
22    #[must_use]
23    pub fn new(msg: impl ToString) -> Self {
24        Self {
25            msg: msg.to_string(),
26        }
27    }
28}
29
30impl From<Infallible> for ModulationError {
31    fn from(_: Infallible) -> Self {
32        unreachable!()
33    }
34}
35
36impl From<SamplingConfigError> for ModulationError {
37    fn from(e: SamplingConfigError) -> Self {
38        Self::new(e)
39    }
40}
41// GRCOV_EXCL_STOP