Skip to main content

embedded_can_socketcan/
non_linux.rs

1use core::fmt;
2
3/// Returned when attempting to use SocketCAN adapters on a non-Linux target.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct UnsupportedPlatformError;
6
7impl fmt::Display for UnsupportedPlatformError {
8    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9        write!(
10            f,
11            "embedded-can-socketcan is only supported on Linux targets"
12        )
13    }
14}
15
16impl std::error::Error for UnsupportedPlatformError {}
17
18/// Classic CAN SocketCAN adapter (non-Linux stub).
19#[derive(Debug, Default)]
20pub struct SocketCan;
21
22impl SocketCan {
23    /// Always returns [`UnsupportedPlatformError`] on non-Linux targets.
24    pub fn open(_iface: &str) -> Result<Self, UnsupportedPlatformError> {
25        Err(UnsupportedPlatformError)
26    }
27}
28
29/// CAN-FD SocketCAN adapter (non-Linux stub).
30#[derive(Debug, Default)]
31pub struct SocketCanFd;
32
33impl SocketCanFd {
34    /// Always returns [`UnsupportedPlatformError`] on non-Linux targets.
35    pub fn open(_iface: &str) -> Result<Self, UnsupportedPlatformError> {
36        Err(UnsupportedPlatformError)
37    }
38}
39
40/// Tokio classic CAN SocketCAN adapter (non-Linux stub).
41#[cfg(feature = "tokio")]
42#[derive(Debug, Default)]
43pub struct TokioSocketCan;
44
45/// Tokio CAN-FD SocketCAN adapter (non-Linux stub).
46#[cfg(feature = "tokio")]
47#[derive(Debug, Default)]
48pub struct TokioSocketCanFd;