### Get CAN Frame Data Payload (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Retrieves the data payload of the CAN frame as a byte slice. The data length is between 0 and 8 bytes. ```rust fn data(&self) -> &[u8] ``` -------------------------------- ### Get CAN Frame Data Length Code (DLC) (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Returns the Data Length Code (DLC) for the CAN frame, which indicates the length of the data payload. The DLC is in the range of 0 to 8. For data frames, DLC matches data length; for remote frames, DLC can be non-zero even without data. ```rust fn dlc(&self) -> usize ``` -------------------------------- ### Get CAN Frame Identifier (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Retrieves the identifier of the CAN frame. The type of the identifier depends on the specific implementation of the `Frame` trait. ```rust fn id(&self) -> Id ``` -------------------------------- ### Rust Nightly CloneToUninit Experimental API Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind An unstable, nightly-only experimental API for performing copy-assignment from self to a mutable byte pointer destination. Requires the `nightly` Rust toolchain. ```rust impl CloneToUninit for T where T: Clone, { unsafe fn clone_to_uninit(&self, dest: *mut u8) { // Implementation details } } ``` -------------------------------- ### TryFrom Conversion Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Details the `try_from` function for performing conversions and its associated error type. ```APIDOC ## `TryFrom` Conversion ### Description Provides functionality to attempt a conversion from one type to another, returning a `Result` that indicates success or failure with a specific error type. ### Method `try_from` ### Endpoint N/A (In-code implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage: let value: U = ...; match >::try_from(value) { Ok(t) => println!("Conversion successful: {:?}", t), Err(e) => println!("Conversion failed: {:?}", e), } ``` ### Response #### Success Response - **Ok(T)**: The successfully converted value of type `T`. #### Error Response - **Err(>::Error)**: An error of the specific conversion error type. #### Response Example ```json // Success: Ok(converted_value) // Error: Err(conversion_error) ``` ``` -------------------------------- ### TryInto Conversion Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Details the `try_into` function for performing conversions and its associated error type, utilizing the `TryFrom` trait. ```APIDOC ## `TryInto` Conversion ### Description Provides functionality to attempt a conversion from the current type (`self`) to another type (`U`), returning a `Result` that indicates success or failure with a specific error type, leveraging the `TryFrom` trait. ### Method `try_into` ### Endpoint N/A (In-code implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage: let t: T = ...; match t.try_into() { Ok(u) => println!("Conversion successful: {:?}", u), Err(e) => println!("Conversion failed: {:?}", e), } ``` ### Response #### Success Response - **Ok(U)**: The successfully converted value of type `U`. #### Error Response - **Err(>::Error)**: An error of the specific conversion error type defined by `U`'s `TryFrom` implementation. #### Response Example ```json // Success: Ok(converted_value) // Error: Err(conversion_error) ``` ``` -------------------------------- ### Rust: Implementing TryInto for Embedded CAN Conversions Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Illustrates the implementation of the `TryInto` trait, which provides a convenient way to perform conversions where the target type implements `TryFrom`. This is commonly used for converting between different CAN message formats or data structures. ```rust impl TryInto for T where U: TryFrom, { type Error = >::Error; fn try_into(self) -> Result { U::try_from(self) } } ``` -------------------------------- ### Rust: Implementing TryFrom for Embedded CAN Conversions Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Demonstrates the implementation of the `TryFrom` trait for custom type conversions within the Embedded CAN context. It details the expected input `U` and output `T`, along with the specific error type returned upon failure. ```rust impl TryFrom for T where U: TryFrom, { type Error = >::Error; fn try_from(value: U) -> Result { // Implementation details for conversion todo!() } } ``` -------------------------------- ### ExtendedId Blanket Implementations (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.ExtendedId Showcases blanket implementations applied to the ExtendedId struct, leveraging generic trait implementations from the Rust standard library. This includes implementations for Any, Borrow, BorrowMut, CloneToUninit, From for T, and Into for T. These are generally provided by the compiler or standard library traits. ```rust // Any impl Any for T where T: 'static + ?Sized { /* ... */ } // Borrow and BorrowMut impl Borrow for T where T: ?Sized { /* ... */ } impl BorrowMut for T where T: ?Sized { /* ... */ } // CloneToUninit (Nightly) impl CloneToUninit for T where T: Clone { /* ... */ } // From for T impl From for T { /* ... */ } // Into for T impl Into for T where U: From { /* ... */ } ``` -------------------------------- ### StandardId Blanket Implementations - Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Shows blanket implementations for StandardId, such as Any, Borrow, BorrowMut, CloneToUninit, From for T, Into for T, and TryFrom for T. These provide generic functionality leveraging Rust's trait system. ```rust impl Any for T impl Borrow for T impl BorrowMut for T impl CloneToUninit for T impl From for T impl Into for T impl TryFrom for T ``` -------------------------------- ### StandardId Trait Implementations - Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Details various trait implementations for StandardId, including Clone, Debug, From for Id, Hash, Ord, PartialEq, and PartialOrd. These traits enable standard Rust operations like copying, printing, hashing, and comparison. ```rust impl Clone for StandardId impl Debug for StandardId impl From for Id impl Hash for StandardId impl Ord for StandardId impl PartialEq for StandardId impl PartialOrd for StandardId ``` -------------------------------- ### StandardId Constants and Creation - Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Provides constants for the minimum (ZERO) and maximum (MAX) StandardId values, along with functions to create StandardId instances. `new` attempts safe creation, while `new_unchecked` offers unsafe creation for performance. ```rust pub const ZERO: Self pub const MAX: Self pub const fn new(raw: u16) -> Option pub unsafe fn new_unchecked(raw: u16) -> Self ``` -------------------------------- ### Define CAN Frame Structure and Methods (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Defines the `Frame` trait, which serves as a blueprint for CAN frame structures. It includes methods for creating frames, checking frame types (standard, extended, remote), and accessing frame identifiers, DLC, and data. The trait is not dyn-compatible. ```rust pub trait Frame: Sized { // Required methods fn new(id: impl Into, data: &[u8]) -> Option; fn new_remote(id: impl Into, dlc: usize) -> Option; fn is_extended(&self) -> bool; fn is_remote_frame(&self) -> bool; fn id(&self) -> Id; fn dlc(&self) -> usize; fn data(&self) -> &[u8]; // Provided methods fn is_standard(&self) -> bool { ... } fn is_data_frame(&self) -> bool { ... } } ``` -------------------------------- ### ExtendedId Trait Implementations (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.ExtendedId Details the various trait implementations for the ExtendedId struct, enabling standard Rust operations. This includes cloning, debugging, conversion to and from other ID types, hashing, ordering (comparison), equality checks, and partial ordering. These traits make ExtendedId compatible with standard collections and operations. ```rust // Clone and Copy impl Clone for ExtendedId { /* ... */ } impl Copy for ExtendedId { /* ... */ } // Debug and Eq impl Debug for ExtendedId { /* ... */ } impl Eq for ExtendedId { /* ... */ } // Conversions impl From for Id { /* ... */ } // Hashing impl Hash for ExtendedId { /* ... */ } // Ordering impl Ord for ExtendedId { /* ... */ } impl PartialOrd for ExtendedId { /* ... */ } // Equality impl PartialEq for ExtendedId { /* ... */ } // Structural Equality impl StructuralPartialEq for ExtendedId { /* ... */ } ``` -------------------------------- ### Rust `TryInto for T` Trait Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.Id The `TryInto for T` trait provides a convenient way to perform fallible conversions from type `T` to type `U`. It leverages the `TryFrom` implementation for the reverse conversion. ```rust /// The type returned in the event of a conversion error. /// This is the `Error` type associated with the `TryFrom` implementation for `U`. type Error = >::Error; /// Performs the conversion. /// Returns a `Result` where `U` is the target type and `Self::Error` is the error type. fn try_into(self) -> Result>::Error>; /// Trait definition for fallible conversions from T to U. impl TryInto for T where U: TryFrom {} ``` -------------------------------- ### Frame Trait Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame The `Frame` trait represents a CAN 2.0 frame and provides methods for creating, querying, and accessing frame data. It includes required methods for frame construction and inspection, as well as provided methods for convenience. ```APIDOC ## Trait Frame ### Description A CAN 2.0 Frame. ### Methods #### `fn new(id: impl Into, data: &[u8]) -> Option` Creates a new frame. Returns `None` if the data slice is too long. **Parameters** - `id` (impl Into): The frame identifier. - `data` (&[u8]): The data payload for the frame. **Returns** - `Option`: A new frame instance if successful, otherwise `None`. #### `fn new_remote(id: impl Into, dlc: usize) -> Option` Creates a new remote frame (RTR bit set). Returns `None` if the data length code (DLC) is not valid. **Parameters** - `id` (impl Into): The frame identifier. - `dlc` (usize): The data length code (0-8). **Returns** - `Option`: A new remote frame instance if successful, otherwise `None`. #### `fn is_extended(&self) -> bool` Returns `true` if this frame is an extended frame. **Returns** - `bool`: `true` for extended frames, `false` otherwise. #### `fn is_remote_frame(&self) -> bool` Returns `true` if this frame is a remote frame. **Returns** - `bool`: `true` for remote frames, `false` otherwise. #### `fn id(&self) -> Id` Returns the frame identifier. **Returns** - `Id`: The frame identifier. #### `fn dlc(&self) -> usize` Returns the data length code (DLC), which is in the range 0..8. For data frames, the DLC value always matches the length of the data. Remote frames do not carry any data, yet the DLC can be greater than 0. **Returns** - `usize`: The data length code. #### `fn data(&self) -> &[u8]` Returns the frame data (0..8 bytes in length). **Returns** - `&[u8]`: A slice containing the frame data. #### `fn is_standard(&self) -> bool` Returns `true` if this frame is a standard frame. **Returns** - `bool`: `true` for standard frames, `false` otherwise. #### `fn is_data_frame(&self) -> bool` Returns `true` if this frame is a data frame. **Returns** - `bool`: `true` for data frames, `false` otherwise. ### Dyn Compatibility This trait is **not** dyn compatible. ``` -------------------------------- ### StandardId Struct Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Represents a standard 11-bit CAN identifier. Provides methods for creating, manipulating, and converting CAN IDs. ```APIDOC ## Struct StandardId ### Description Standard 11-bit CAN Identifier (`0..=0x7FF`). ### Methods #### `pub const ZERO: Self` CAN ID `0`, the highest priority. #### `pub const MAX: Self` CAN ID `0x7FF`, the lowest priority. #### `pub const fn new(raw: u16) -> Option` Tries to create a `StandardId` from a raw 16-bit integer. This will return `None` if `raw` is out of range of an 11-bit integer (`> 0x7FF`). #### `pub const unsafe fn new_unchecked(raw: u16) -> Self` Creates a new `StandardId` without checking if it is inside the valid range. **Safety:** Using this method can create an invalid ID and is thus marked as unsafe. #### `pub fn as_raw(&self) -> u16` Returns this CAN Identifier as a raw 16-bit integer. ### Trait Implementations - **`Clone`**: Allows creating copies of `StandardId`. - **`Debug`**: Enables debugging output for `StandardId`. - **`From for Id`**: Converts `StandardId` into an `Id` type. - **`Hash`**: Allows hashing `StandardId` for use in hash maps. - **`Ord`**: Provides total ordering for `StandardId`, enabling comparisons. - **`PartialOrd`**: Provides partial ordering for `StandardId`. - **`PartialEq`**: Enables equality comparison for `StandardId`. - **`Eq`**: Indicates that equality is reflexive, symmetric, and transitive. - **`Copy`**: Allows `StandardId` to be copied implicitly. - **`StructuralPartialEq`**: Enables structural equality checks. ``` -------------------------------- ### Create New CAN Frame (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Provides a method to create a new CAN frame with a given identifier and data payload. Returns `None` if the provided data slice exceeds the maximum allowed length. ```rust fn new(id: impl Into, data: &[u8]) -> Option ``` -------------------------------- ### Rust `into()` Method for Conversions Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.Id The `into()` method calls `U::from(self)`, enabling conversions based on the `From for U` trait implementation. This is useful for straightforward type transformations where an error is not expected. ```rust /// Calls `U::from(self)`. /// That is, this conversion is whatever the implementation of `From for U` chooses to do. fn into(self) -> U; ``` -------------------------------- ### Transmit CAN Frame Method for Embedded Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/nb/trait.Can Implements the `transmit` method for the `Can` trait in embedded Rust. This function attempts to send a CAN frame, managing the transmit buffer. It can return a replaced frame if the buffer is full and a lower priority frame is preempted, or an error if the buffer is full and no replacement is possible. ```rust fn transmit( &mut self, frame: &Self::Frame, ) -> Result, Self::Error> ``` -------------------------------- ### Rust From Trait Implementation Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind A trait for converting between types. The `from` function simply returns the argument unchanged, indicating a trivial conversion. ```rust impl From for T { fn from(t: T) -> T { t } } ``` -------------------------------- ### ExtendedId Auto Trait Implementations (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.ExtendedId Lists the auto-derived trait implementations for the ExtendedId struct, indicating its thread-safety and memory management characteristics. These include Send, Sync, Unpin, Freeze, RefUnwindSafe, and UnwindSafe, which are crucial for safe concurrent programming and memory handling in Rust. ```rust impl Freeze for ExtendedId {} impl RefUnwindSafe for ExtendedId {} impl Send for ExtendedId {} impl Sync for ExtendedId {} impl Unpin for ExtendedId {} impl UnwindSafe for ExtendedId {} ``` -------------------------------- ### Create New Remote Transmission Request (RTR) Frame (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Provides a method to create a new CAN remote transmission request (RTR) frame. An RTR frame requests data from another node. Returns `None` if the specified data length code (DLC) is invalid. ```rust fn new_remote(id: impl Into, dlc: usize) -> Option ``` -------------------------------- ### ExtendedId Struct Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.ExtendedId Details about the ExtendedId struct, which represents a 29-bit CAN Identifier. ```APIDOC ## Struct ExtendedId Represents an Extended 29-bit CAN Identifier (0..=1FFF_FFFF). ### Constants - **`ZERO`**: `Self` - CAN ID `0`, the highest priority. - **`MAX`**: `Self` - CAN ID `0x1FFFFFFF`, the lowest priority. ### Constructor - **`new(raw: u32) -> Option`**: Tries to create an `ExtendedId` from a raw 32-bit integer. Returns `None` if `raw` is out of the 29-bit range (`> 0x1FFF_FFFF`). - **`new_unchecked(raw: u32) -> Self`**: Creates a new `ExtendedId` without checking if it is inside the valid range. This method is `unsafe` as it can create an invalid ID. ### Methods - **`as_raw(&self) -> u32`**: Returns this CAN Identifier as a raw 32-bit integer. - **`standard_id(&self) -> StandardId`**: Returns the Base ID part of this extended identifier. ### Trait Implementations - **`Clone`**: Allows creating copies of `ExtendedId`. - **`Debug`**: Formats the `ExtendedId` for debugging. - **`From for Id`**: Converts an `ExtendedId` into an `Id` type. - **`Hash`**: Enables hashing of `ExtendedId`. - **`Ord`**: Provides ordering comparisons for `ExtendedId`. - **`PartialOrd`**: Provides partial ordering comparisons for `ExtendedId`. - **`PartialEq`**: Enables equality comparisons for `ExtendedId`. - **`Copy`**: Allows `ExtendedId` to be copied implicitly. - **`Eq`**: Marks `ExtendedId` as having a total equivalence relation. - **`StructuralPartialEq`**: Structural equality comparison. ``` -------------------------------- ### Can Trait Transmit Method (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/blocking/trait.Can Implements the 'transmit' method for the 'Can' trait. This function is responsible for placing a CAN frame into the transmit buffer and will block until there is available space. It returns a Result to indicate success or failure. ```Rust fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error> ``` -------------------------------- ### StandardId Auto Trait Implementations - Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Lists the auto trait implementations for StandardId, including Send, Sync, Unpin, Freeze, RefUnwindSafe, and UnwindSafe. These indicate thread safety and memory management characteristics of the struct. ```rust impl Freeze for StandardId impl RefUnwindSafe for StandardId impl Send for StandardId impl Sync for StandardId impl Unpin for StandardId impl UnwindSafe for StandardId ``` -------------------------------- ### Rust Into Trait Implementation Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind Enables converting a type `T` into another type `U` where `U` implements `From`. This is the reciprocal of the `From` trait. ```rust impl Into for T where U: From, { fn into(self) -> U { U::from(self) } } ``` -------------------------------- ### Blocking CAN Interface Source: https://docs.rs/embedded-can/0.4.1/embedded_can/blocking/trait.Can The `Can` trait defines a blocking interface for transmitting and receiving CAN frames. It specifies associated types for frames and errors, along with methods for transmission and reception. ```APIDOC ## Trait embedded_can::blocking::Can ### Description A blocking CAN interface that is able to transmit and receive frames. ### Associated Types #### type Frame: Frame Associated frame type. #### type Error: Error Associated error type. ### Methods #### fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error> Puts a frame in the transmit buffer. Blocks until space is available in the transmit buffer. ##### Parameters - **frame** (*Self::Frame*) - Required - The CAN frame to transmit. ##### Returns - `Result<(), Self::Error>` - Ok(()) if the frame was successfully placed in the transmit buffer, or an error if transmission failed. #### fn receive(&mut self) -> Result Blocks until a frame was received or an error occured. ##### Returns - `Result` - The received CAN frame or an error if reception failed. ``` -------------------------------- ### Rust TryInto Trait Implementation Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind The reciprocal of `TryFrom`, allowing fallible conversions from type `T` into type `U`. It returns a `Result` which may contain an error type defined by the `TryFrom` implementation. ```rust impl TryInto for T where U: TryFrom, { type Error = > ::Error; fn try_into(self) -> Result> ::Error> { U::try_from(self) } } ``` -------------------------------- ### Define CAN Error Handling with Error Trait (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Error The `Error` trait in `embedded-can` provides a standardized way to represent and handle errors from CAN peripherals. Implement this trait to convert HAL-specific errors into a generic `ErrorKind` for unified error management in your embedded applications. Dependencies include the `Debug` trait. ```Rust pub trait Error: Debug { // Required method fn kind(&self) -> ErrorKind; } ``` -------------------------------- ### Can Trait Receive Method (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/blocking/trait.Can Implements the 'receive' method for the 'Can' trait. This function blocks until a CAN frame is successfully received or an error occurs. It returns a Result containing the received frame or an error. ```Rust fn receive(&mut self) -> Result ``` -------------------------------- ### Rust TryFrom Trait Implementation Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind Facilitates fallible conversions between types. The `try_from` function returns a `Result` indicating success or failure, with `Infallible` as the error type for this specific implementation. ```rust use std::convert::Infallible; impl TryFrom for T where U: Into, { type Error = Infallible; fn try_from(value: U) -> Result { Ok(value.into()) } } ``` -------------------------------- ### StandardId Raw Value Conversion - Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId A method to retrieve the underlying 16-bit raw integer representation of a StandardId. This is useful for interacting with hardware or other systems that expect a raw integer ID. ```rust pub fn as_raw(&self) -> u16 ``` -------------------------------- ### Rust `TryFrom for T` Trait Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.Id The `TryFrom for T` trait allows for fallible conversions from type `U` to type `T`. It is used when a conversion might fail, requiring an error type to be specified. ```rust /// The type returned in the event of a conversion error. /// This is `Infallible` for `TryFrom for T` where `U: Into`. type Error = Infallible; /// Performs the conversion. /// Returns a `Result` where `T` is the target type and `Self::Error` is the error type. fn try_from(value: U) -> Result>::Error>; /// Trait definition for fallible conversions from U to T. impl TryFrom for T where U: Into {} ``` -------------------------------- ### Define ExtendedId CAN Identifier (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.ExtendedId Defines the ExtendedId struct for representing a 29-bit CAN identifier (0 to 0x1FFF_FFFF). It includes constants for zero and maximum values, methods for safe and unsafe creation from a raw u32, and a method to retrieve the raw value. This struct is fundamental for working with extended CAN frames. ```rust pub struct ExtendedId(/* private fields */); impl ExtendedId { /// CAN ID `0`, the highest priority. pub const ZERO: Self; /// CAN ID `0x1FFFFFFF`, the lowest priority. pub const MAX: Self; /// Tries to create a `ExtendedId` from a raw 32-bit integer. /// This will return `None` if `raw` is out of range of an 29-bit integer (`> 0x1FFF_FFFF`). pub const fn new(raw: u32) -> Option; /// Creates a new `ExtendedId` without checking if it is inside the valid range. /// /// # Safety /// Using this method can create an invalid ID and is thus marked as unsafe. pub unsafe fn new_unchecked(raw: u32) -> Self; /// Returns this CAN Identifier as a raw 32-bit integer. pub fn as_raw(&self) -> u32; /// Returns the Base ID part of this extended identifier. pub fn standard_id(&self) -> StandardId; } ``` -------------------------------- ### Can Trait Definition for Embedded Rust CAN Interfaces Source: https://docs.rs/embedded-can/0.4.1/embedded_can/nb/trait.Can Defines the `Can` trait, an essential interface for CAN communication in embedded Rust. It specifies associated types for frames and errors, and methods for transmitting and receiving CAN frames. Implementors must provide concrete types for `Frame` and `Error`, and logic for `transmit` and `receive` operations, handling potential blocking scenarios. ```rust pub trait Can { type Frame: Frame; type Error: Error; // Required methods fn transmit( &mut self, frame: &Self::Frame, ) -> Result, Self::Error>; fn receive(&mut self) -> Result; } ``` -------------------------------- ### Implement Error Trait for Infallible Type (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Error Demonstrates the implementation of the `Error` trait for the `Infallible` type, which represents operations that cannot fail. This specific implementation of the `kind` method would likely indicate no error occurred. ```Rust impl Error for Infallible { fn kind(&self) -> ErrorKind; } ``` -------------------------------- ### Can Trait Definition for Blocking CAN Interface (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/blocking/trait.Can Defines the 'Can' trait for a blocking CAN interface. It specifies associated types for frames and errors, and methods for transmitting and receiving frames. This trait is fundamental for interacting with CAN hardware in a synchronous manner. ```Rust pub trait Can { type Frame: Frame; type Error: Error; // Required methods fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>; fn receive(&mut self) -> Result; } ``` -------------------------------- ### StandardId Struct Definition - Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/struct.StandardId Defines the StandardId struct, representing an 11-bit CAN identifier. It includes private fields and is used to manage standard CAN IDs ranging from 0 to 0x7FF. ```rust pub struct StandardId(/* private fields */); ``` -------------------------------- ### Convert Error to Generic CAN Error Kind (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Error The `kind` method is a required part of the `Error` trait. It allows the conversion of custom CAN error types into a generic `ErrorKind` enum. This facilitates writing generic code that can handle errors from various CAN controllers and HAL implementations uniformly. ```Rust fn kind(&self) -> ErrorKind; ``` -------------------------------- ### Rust BorrowMut Trait Implementation Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind Provides a mutable reference to an owned value. This is a fundamental trait for mutable access in Rust. ```rust impl BorrowMut for T where T: ?Sized, { fn borrow_mut(&mut self) -> &mut T { // Implementation details } } ``` -------------------------------- ### ErrorKind Enum Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind The ErrorKind enum represents common CAN operation errors. HAL implementations can define more specific errors but should map them to these common types for generic code compatibility. ```APIDOC ## Enum ErrorKind ### Description This enum represents a common set of CAN operation errors. HAL implementations are free to define more specific or additional error types. By providing a mapping to these common CAN errors, generic code can still react to them. ### Variants (Non-exhaustive) This enum is marked as non-exhaustive, meaning future versions may add more variants. A wildcard arm should be included when matching to handle potential future variants. * **Overrun**: The peripheral receive buffer was overrun. * **Bit**: A bit error is detected when the monitored bit value differs from the sent bit value. * **Stuff**: A stuff error is detected after six consecutive equal bit levels in a frame field that requires bit stuffing. * **Crc**: The calculated CRC sequence does not match the received one. * **Form**: A form error is detected when a fixed-form bit field contains illegal bits. * **Acknowledge**: An ACK error is detected by a transmitter if it does not monitor a dominant bit during the ACK slot. * **Other**: A different, unspecified error occurred. The original error may contain more information. ``` -------------------------------- ### Check if CAN Frame is Standard (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Determines if the CAN frame uses the standard identifier format (11-bit ID). Returns `true` for standard frames and `false` for extended frames. ```rust fn is_standard(&self) -> bool ``` -------------------------------- ### Implement Error Trait for ErrorKind Type (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Error Shows the implementation of the `Error` trait for the `ErrorKind` enum itself. This allows `ErrorKind` values to be treated as errors conforming to the `Error` trait, potentially for recursive error handling or convenience. ```Rust impl Error for ErrorKind ``` -------------------------------- ### Define CAN Identifier Enum (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.Id Defines the `Id` enum for representing CAN identifiers. It can be either a `Standard` 11-bit identifier or an `Extended` 29-bit identifier. This enum supports conversions from `StandardId` and `ExtendedId` and implements comparison logic according to CAN arbitration rules. ```rust pub enum Id { Standard(StandardId), Extended(ExtendedId), } ``` -------------------------------- ### Check if CAN Frame is Extended (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame A method to determine if a CAN frame uses the extended identifier format (29-bit ID). Returns `true` if it's an extended frame, `false` otherwise. ```rust fn is_extended(&self) -> bool ``` -------------------------------- ### Check if CAN Frame is a Data Frame (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame Checks if the CAN frame is a data frame, meaning it contains actual data to be transmitted. Returns `true` for data frames and `false` for remote transmission request (RTR) frames. ```rust fn is_data_frame(&self) -> bool ``` -------------------------------- ### Define CAN Error Kind Enum in Rust Source: https://docs.rs/embedded-can/0.4.1/embedded_can/enum.ErrorKind This Rust code defines the `ErrorKind` enum, which enumerates common errors that can occur during CAN operations. It is marked as non-exhaustive, allowing for future additions. The enum includes variants like Overrun, Bit, Stuff, Crc, Form, Acknowledge, and Other. HAL implementations can map their specific errors to these common types. ```rust #[non_exhaustive] pub enum ErrorKind { Overrun, Bit, Stuff, Crc, Form, Acknowledge, Other, } ``` -------------------------------- ### Check if CAN Frame is a Remote Frame (Rust) Source: https://docs.rs/embedded-can/0.4.1/embedded_can/trait.Frame A method to check if the CAN frame is a remote transmission request (RTR) frame. Returns `true` if it's an RTR frame, `false` if it's a data frame. ```rust fn is_remote_frame(&self) -> bool ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.