-
Notifications
You must be signed in to change notification settings - Fork 269
Conversation
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.
Strange signature.
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.
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.
adamgreig
commented
Apr 2, 2024
Thanks for the PR! We had a brief discussion about it in the weekly meeting today. Having the trait in the asynch module is fine. I think the only remaining question is whether to keep the try_x() methods, move to to another trait, or delete them entirely.
It looks like either the crate's MSRV (and related CI tests) will need updating, or the trait needs to be gated, to get CI passing, too.
liamkinne
commented
Apr 4, 2024
@adamgreig thanks for the update.
I'm still strongly for keeping the try methods. The use case is that when libraries (bxcan, fdcan, etc) implement these traits they can only implement one trait at a time so they will have a blocking client and an async client. If you're using the async client but need to do something in a non-async context (think RTIC hardware task) you need something to fallback to that doesn't require .await.
It is very similar to the ideas around nb but more like "hey this method will work first time most of the time, unless your buffer is full which you can chose how to handle".
liamkinne
commented
Jun 27, 2024
@adamgreig in the interest of getting this through so it can start being used downstream, I've removed the try methods.
adamgreig
commented
Jun 30, 2024
Thanks for the prompt and the update. I'll add this to the agenda for discussion in the weekly meeting this Tues.
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.
these cfg_attrs do nothing without this in build.rs.
These were for compat with older nightlies before AFIT was stable. Now that AFIT has been stable for a few rust versions since 1.75, i'd just not put them, and support stable 1.75+ only.
b8f8ec1 to
37f4be6
Compare
elpiel
commented
Dec 6, 2024
Are there any blockers for this PR?
@MabezDev
MabezDev
left a comment
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.
Based on https://github.com/rust-embedded/embedded-hal/blob/master/docs/how-to-add-a-new-trait.md we should encourage some experimentation here.
IMO with CI fixed, we should merge this it looks like a good first run to me and time will tell if it's suitable in the long term.
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
fn transmit(&mut self, frame: &Self::Frame) -> Future<Output=Result<(), Self::Error>>;
to avoid needing #![allow(async_fn_in_trait)] (which iirc will be deprecated in the future). you can still implement using async fn in either case.
What is the state of this PR? async fn in traits should now work without any additional attributes, right?
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.
is this still required on stable Rust?
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.
It is not, however, an appropriate MSRV should be used in Cargo.toml for this.
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.
It is required for the MSRV listed in the Cargo.toml (1.81). Do you want me to keep it or bump the MSRV?
37f4be6 to
94b2c2d
Compare
liamkinne
commented
Aug 8, 2025
Before I go any further on this, do we want a single trait to encapsulate transmit and receive or would it be better split into a Tx and Rx trait?
swobbee-dev
commented
Aug 9, 2025
I would like to chime in as I have been using this branch for a project for some time now, I actually did implement the split method in my fork because I needed exactly that: https://github.com/swobbee-dev/embedded-hal/tree/feature/embedded-can-async
Therefore I would be greatly in favour of splitting 👍
5d35622 to
68d91c8
Compare
liamkinne
commented
Jan 24, 2026
@adamgreig I've rebased this so it is ready for review again. Notable changes since last time is the trait is now split into tx and rx.
@eldruin
eldruin
left a comment
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.
Thank you for this!
Would it be possible to remove the async_fn_in_trait feature if rewriting the signatures like this like stated above?
fn transmit(&mut self, frame: &Self::Frame) -> Future<Output=Result<(), Self::Error>>;
Then we do not need to touch the MSRV. What version would not need it?
liamkinne
commented
Jan 27, 2026
@eldruin no worries. Have updated the function signatures and left the MSRV as is.
@eldruin
eldruin
left a comment
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.
This looks good to me, thank you!
Do you have any implementations of the trait somewhere?
mickeprag
commented
Jan 28, 2026
Do you have any implementations of the trait somewhere?
I am currently waiting for this PR before using it here:
ch32-rs/ch32-hal#146
liamkinne
commented
Jan 28, 2026
Looking at the embassy fdcan implementation, I realised there's something missing from the transmit signature. It needs to return Ok(Option<Frame>) in the case that the transmit mailboxes are full. This is the existing API with the non-blocking traits.
Adds a new CAN trait with both async and fallback non-blocking methods.
Module is named
asynchto avoid a collision with theasynckeyword. Alternatively a separate crateembedded-can-asynccould be published.