autd3_core/gain/
error.rs

1#[derive(Debug, PartialEq, Clone)]
2/// An error occurred during gain calculation.
3pub struct GainError {
4    msg: String,
5}
6
7impl core::fmt::Display for GainError {
8    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9        write!(f, "{}", self.msg)
10    }
11}
12
13impl core::error::Error for GainError {}
14
15impl GainError {
16    /// Creates a new [`GainError`].
17    #[must_use]
18    pub fn new(msg: impl ToString) -> Self {
19        Self {
20            msg: msg.to_string(),
21        }
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn test_gain_error_display() {
31        let err = GainError::new("Test error");
32        assert_eq!(format!("{}", err), "Test error");
33    }
34}