rust-iot / radio-hal

Embedded rust radio abstraction crate
https://ryan.kurte.nz/notes/2020-01-05-rust-radio
MIT License
69 stars 13 forks source link

Return Info directly from Receive #14

Closed Tortoaster closed 2 years ago

Tortoaster commented 2 years ago

This PR moves the ReceiveInfo from Receive's get_received method from its parameters to the return type. Originally, one would need to create Info::default() and then have get_received alter it. Now, get_received has to create the Info itself. This removes the need for a Default trait bound, and simplifies the caller code a bit.

You mentioned GATs not being available as the reason Info was a parameter, but I'm not sure why, as I didn't use GATs here. :grin:

As such, take this PR with a grain of salt for now, but I would love to know how it can be improved!

ryankurte commented 2 years ago

Thanks for the PR @Tortoaster!

You mentioned GATs not being available as the reason Info was a parameter, but I'm not sure why, as I didn't use GATs here.

i might have crossed wires commenting on things but, associated type bounds was what i was going for. the trick that lets us make traits generic over a future without boxing, like:

pub trait AsyncTransmit<'a, E> {
    type Output: Future<Output=Result<(), AsyncError<E>>>;
...
}

you might always have been able to do the simple version, it's been a while and i can't quite remember where the issues were prior to at least part of this landing 😂

the PR looks good, though i have already made this change (with a bit of other houscleaning) over in https://github.com/rust-iot/radio-hal/pull/13. given that's already been reviewed i've tagged you as a co-author over there, hope that's alright and doesn't dissuade you from making other contributions ^_^