autd3_core/link/
error.rs

1use derive_more::Display;
2use thiserror::Error;
3
4#[derive(Error, Debug, Display, PartialEq, Clone)]
5#[display("{}", msg)]
6/// An error produced by the link.
7pub struct LinkError {
8    msg: String,
9}
10
11impl LinkError {
12    /// Creates a new [`LinkError`].
13    #[must_use]
14    pub fn new(msg: impl ToString) -> LinkError {
15        LinkError {
16            msg: msg.to_string(),
17        }
18    }
19
20    /// Creates a new [`LinkError`] with a message indicating that the link is closed.
21    pub fn closed() -> LinkError {
22        LinkError::new("Link is closed")
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn link_error_closed() {
32        let err = LinkError::closed();
33        assert_eq!("Link is closed", err.to_string());
34    }
35}