Skip to main content

autd3_rs_core/link/
interface.rs

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