can_socket/
interface.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
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
pub struct CanInterface {
	pub(crate) inner: crate::sys::CanInterface,
}

impl CanInterface {
	pub fn from_index(index: u32) -> Self {
		Self {
			inner: crate::sys::CanInterface::from_index(index),
		}
	}

	pub fn from_name(name: &str) -> std::io::Result<Self> {
		Ok(Self {
			inner: crate::sys::CanInterface::from_name(name)?,
		})
	}

	pub fn index(&self) -> u32 {
		self.inner.index()
	}

	pub fn get_name(&self) -> std::io::Result<String> {
		self.inner.get_name()
	}
}

impl std::fmt::Debug for CanInterface {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		let name = self.get_name();
		let mut debug = f.debug_struct("CanInterface");
		debug.field("index", &self.index());
		if let Ok(name) = &name {
			debug.field("name", name);
		}
		debug.finish()
	}
}