Skip to main content

autd3_rs_core/link/
interface.rs

1#[derive(Clone, Debug, Default, PartialEq, Eq)]
2#[non_exhaustive]
3pub enum Interface {
4    #[default]
5    Auto,
6    Name(String),
7}
8
9impl Interface {
10    #[must_use]
11    pub fn name(&self) -> Option<&str> {
12        match self {
13            Interface::Auto => None,
14            Interface::Name(name) => Some(name),
15        }
16    }
17}
18
19impl From<String> for Interface {
20    fn from(name: String) -> Self {
21        Interface::Name(name)
22    }
23}
24
25impl From<&str> for Interface {
26    fn from(name: &str) -> Self {
27        Interface::Name(name.to_owned())
28    }
29}
30
31impl<T: Into<Interface>> From<Option<T>> for Interface {
32    fn from(opt: Option<T>) -> Self {
33        opt.map_or(Interface::Auto, Into::into)
34    }
35}