yoshuawuyts / futures-concurrency

Structured concurrency operations for async Rust
https://docs.rs/futures-concurrency
Apache License 2.0
400 stars 31 forks source link

Add no-std support #163

Closed alexmoon closed 6 months ago

alexmoon commented 8 months ago

Adds std and alloc features to enable support for no-std targets.

Mostly this was just a matter of updating imports from std to core or alloc as necessary along with cfg directives to omit things like the vec implementations that require an allocator.

The only real issue I ran into was that the implementations of WakerArray and WakerVec required both Arc and Mutex. Arc is only available on alloc and Mutex is only available on std. So I've added very basic no-std implementations of both which simply revert to using the parent waker directly instead of trying to do precise waking. I think it should be possible to implement precise waking in a no-std environment, but will require messing with RawWakers and probably pinning and a fair amount of unsafe code. This does mean that on no-std targets all futures will be polled on every wake.

The only other behavior difference is removing printing of the child error sources in the Debug impl of the AggregateError structs. This was necessary because the Error trait is currently std only. It does have the side benefit of there now being a Debug impl for any AggregateError whose T impls Display instead of only when T impls Error.

I updated CI to run cargo check on std, alloc, and core configurations. Let me know if you want CI to run cargo test on the no-std configurations as well.

max-heller commented 7 months ago

I'm excited for this as I'd like to use this crate in a no-std, minimal-alloc environment. Even if precise waking isn't possible, it'd be great to have access to these combinators workout having to reinvent the wheel!