pub struct CanSocket(/* private fields */);
Expand description
A socket for classic CAN 2.0 devices.
This provides an interface to read and write classic CAN 2.0 frames to the bus, with up to 8 bytes of data per frame. It wraps a Linux socket descriptor to a Raw SocketCAN socket.
The socket is automatically closed when the object is dropped. To close manually, use std::drop::Drop. Internally this is just a wrapped socket (file) descriptor.
Implementations§
Trait Implementations§
Source§impl AsFd for CanSocket
impl AsFd for CanSocket
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl Can for CanSocket
impl Can for CanSocket
Source§fn receive(&mut self) -> Result<Self::Frame>
fn receive(&mut self) -> Result<Self::Frame>
Blocking call to receive the next frame from the bus.
This block and wait for the next frame to be received from the bus.
If an error frame is received, it will be converted to a CanError
and returned as an error.
Source§impl Can for CanSocket
impl Can for CanSocket
Source§fn receive(&mut self) -> Result<Self::Frame, Self::Error>
fn receive(&mut self) -> Result<Self::Frame, Self::Error>
Non-blocking call to receive the next frame from the bus.
If an error frame is received, it will be converted to a CanError
and returned as an error.
If no frame is available, it returns a WouldBlck
error.
Source§impl IntoRawFd for CanSocket
impl IntoRawFd for CanSocket
Source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
Source§impl Read for CanSocket
impl Read for CanSocket
Source§fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl Socket for CanSocket
impl Socket for CanSocket
Source§fn as_raw_socket(&self) -> &Socket ⓘ
fn as_raw_socket(&self) -> &Socket ⓘ
Gets a shared reference to the underlying socket object
Source§fn as_raw_socket_mut(&mut self) -> &mut Socket ⓘ
fn as_raw_socket_mut(&mut self) -> &mut Socket ⓘ
Gets a mutable reference to the underlying socket object
Source§fn write_frame<F>(&self, frame: &F) -> IoResult<()>
fn write_frame<F>(&self, frame: &F) -> IoResult<()>
Writes a normal CAN 2.0 frame to the socket.
Source§fn read_frame(&self) -> IoResult<CanFrame>
fn read_frame(&self) -> IoResult<CanFrame>
Reads a normal CAN 2.0 frame from the socket.
Source§fn open_iface(ifindex: u32) -> IoResult<Self>where
Self: Sized,
fn open_iface(ifindex: u32) -> IoResult<Self>where
Self: Sized,
Source§fn nonblocking(&self) -> IoResult<bool>
fn nonblocking(&self) -> IoResult<bool>
Source§fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()>
fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()>
Source§fn read_timeout(&self) -> IoResult<Option<Duration>>
fn read_timeout(&self) -> IoResult<Option<Duration>>
Source§fn set_read_timeout<D>(&self, duration: D) -> IoResult<()>
fn set_read_timeout<D>(&self, duration: D) -> IoResult<()>
Source§fn write_timeout(&self) -> IoResult<Option<Duration>>
fn write_timeout(&self) -> IoResult<Option<Duration>>
Source§fn set_write_timeout<D>(&self, duration: D) -> IoResult<()>
fn set_write_timeout<D>(&self, duration: D) -> IoResult<()>
Source§impl SocketOptions for CanSocket
impl SocketOptions for CanSocket
Source§fn set_socket_option<T>(
&self,
level: c_int,
name: c_int,
val: &T,
) -> IoResult<()>
fn set_socket_option<T>( &self, level: c_int, name: c_int, val: &T, ) -> IoResult<()>
Source§fn set_socket_option_mult<T>(
&self,
level: c_int,
name: c_int,
values: &[T],
) -> IoResult<()>
fn set_socket_option_mult<T>( &self, level: c_int, name: c_int, values: &[T], ) -> IoResult<()>
Source§fn set_filters<F>(&self, filters: &[F]) -> IoResult<()>
fn set_filters<F>(&self, filters: &[F]) -> IoResult<()>
Source§fn set_filter_accept_all(&self) -> IoResult<()>
fn set_filter_accept_all(&self) -> IoResult<()>
Source§fn set_error_filter(&self, mask: u32) -> IoResult<()>
fn set_error_filter(&self, mask: u32) -> IoResult<()>
Source§fn set_error_filter_drop_all(&self) -> IoResult<()>
fn set_error_filter_drop_all(&self) -> IoResult<()>
Source§fn set_error_filter_accept_all(&self) -> IoResult<()>
fn set_error_filter_accept_all(&self) -> IoResult<()>
Source§fn set_error_mask(&self, mask: u32) -> IoResult<()>
fn set_error_mask(&self, mask: u32) -> IoResult<()>
Source§impl TryFrom<CanSocket> for CanFdSocket
impl TryFrom<CanSocket> for CanFdSocket
Source§impl Write for CanSocket
impl Write for CanSocket
Source§fn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
Source§fn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Auto Trait Implementations§
impl Freeze for CanSocket
impl RefUnwindSafe for CanSocket
impl Send for CanSocket
impl Sync for CanSocket
impl Unpin for CanSocket
impl UnwindSafe for CanSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<R> ReadBytesExt for R
impl<R> ReadBytesExt for R
Source§fn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
Source§fn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
Source§fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
Source§fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
Source§fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Source§fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Source§fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Source§fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Source§fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
Source§fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
Source§fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
Source§fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
Source§fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
Source§fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
Source§fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
Source§fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
read_f32_into
instead