Skip to content
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 no-std support #163

Merged
merged 1 commit into from
Mar 11, 2024
Merged

Add no-std support #163

merged 1 commit into from
Mar 11, 2024

Conversation

alexmoon
Copy link
Contributor

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.

@alexmoon alexmoon mentioned this pull request Jan 28, 2024
@max-heller
Copy link

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!

Copy link
Owner

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic, thank you!

Apologies for taking a minute to review this; I was out of office all of December and this fell off my review queue. I'm very grateful for this PR though, as support for no_std and alloc environments is really important! I've gone and filed #166 as well to make sure we eventually improve the performance as well.

@yoshuawuyts yoshuawuyts merged commit d6f70c7 into yoshuawuyts:main Mar 11, 2024
5 checks passed
@alexmoon alexmoon deleted the no-std branch April 12, 2024 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants