autd3_core/modulation/
error.rs

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
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::{convert::Infallible, time::Duration};

use derive_more::Display;
use derive_new::new;
use thiserror::Error;

use crate::defined::Freq;

#[derive(new, Error, Debug, Display, PartialEq, Clone)]
#[display("{}", msg)]
/// An error occurred during modulation calculation.
pub struct ModulationError {
    msg: String,
}

#[derive(Error, Debug, PartialEq, Copy, Clone)]
/// An error produced by the sampling configuration.
pub enum SamplingConfigError {
    /// Invalid sampling division.
    #[error("Sampling division must not be zero")]
    SamplingDivisionInvalid,
    /// Invalid sampling frequency.
    #[error("Sampling frequency ({0:?}) must divide the ultrasound frequency")]
    SamplingFreqInvalid(Freq<u32>),
    /// Invalid sampling frequency.
    #[error("Sampling frequency ({0:?}) must divide the ultrasound frequency")]
    SamplingFreqInvalidF(Freq<f32>),
    /// Invalid sampling period.
    #[error("Sampling period ({0:?}) must be a multiple of the ultrasound period")]
    SamplingPeriodInvalid(Duration),
    /// Sampling frequency is out of range.
    #[error("Sampling frequency ({0:?}) is out of range ([{1:?}, {2:?}])")]
    SamplingFreqOutOfRange(Freq<u32>, Freq<u32>, Freq<u32>),
    /// Sampling frequency is out of range.
    #[error("Sampling frequency ({0:?}) is out of range ([{1:?}, {2:?}])")]
    SamplingFreqOutOfRangeF(Freq<f32>, Freq<f32>, Freq<f32>),
    /// Sampling period is out of range.
    #[error("Sampling period ({0:?}) is out of range ([{1:?}, {2:?}])")]
    SamplingPeriodOutOfRange(Duration, Duration, Duration),
}

// GRCOV_EXCL_START
impl From<Infallible> for SamplingConfigError {
    fn from(_: Infallible) -> Self {
        unreachable!()
    }
}

impl From<Infallible> for ModulationError {
    fn from(_: Infallible) -> Self {
        unreachable!()
    }
}

impl From<SamplingConfigError> for ModulationError {
    fn from(e: SamplingConfigError) -> Self {
        Self::new(e.to_string())
    }
}
// GRCOV_EXCL_STOP