-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async API for CAN #585
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Async CAN API | ||
|
||
/// An async CAN interface that is able to transmit and receive frames. | ||
pub trait Can { | ||
/// Associated frame type. | ||
type Frame: crate::Frame; | ||
|
||
/// Associated error type. | ||
type Error: crate::Error; | ||
|
||
/// Puts a frame in the transmit buffer. | ||
/// Awaits until space is available in the transmit buffer. | ||
async fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>; | ||
|
||
/// Tries to put a frame in the transmit buffer. | ||
/// If no space is available in the transmit buffer `None` is returned. | ||
fn try_transmit(&mut self, frame: &Self::Frame) -> Option<Result<(), Self::Error>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange signature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inspired by a pattern I've seen around like here: https://docs.rs/rtic-sync/latest/rtic_sync/arbiter/struct.Arbiter.html Can just get rid of it, but I think it's useful. |
||
|
||
/// Awaits until a frame was received or an error occurred. | ||
async fn receive(&mut self) -> Result<Self::Frame, Self::Error>; | ||
|
||
/// Tries to receive a frame from the receive buffer. | ||
/// If no frame is available `None` is returned. | ||
fn try_receive(&mut self) -> Option<Result<Self::Frame, Self::Error>>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think these should be in the form
to avoid needing
#![allow(async_fn_in_trait)]
(which iirc will be deprecated in the future). you can still implement usingasync fn
in either case.