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

Implement support for no_std #64

Merged
merged 6 commits into from Feb 8, 2022
Merged

Implement support for no_std #64

merged 6 commits into from Feb 8, 2022

Conversation

wackbyte
Copy link
Contributor

@wackbyte wackbyte commented Jan 4, 2022

I added a std feature to support building with no_std.

If enabled, it implements the Error trait and uses std's HashSet.
Otherwise, it doesn't implement Error and uses hashbrown's HashSet.

However, there are a few details I'd like to hear your opinion on if I need to make some changes.

  • no_std is disabled in documentation.
  • Because of Optional dependency when a feature is *not* enabled. rust-lang/cargo#1839, the dependency on hashbrown can't be optional. It could probably be if there was a no_std feature instead, but according to the feature reference in the Cargo book, features should be additive, and a std feature should be used over a no_std one.
  • I looked into hashbrown and found that it uses ahash by default (through a default feature), so I removed the direct dependency on it and used it through hashbrown. This may be undesirable.
  • The Verbose struct in the debug module currently uses the print! macros. Since those do not exist in a no_std environment, the function that uses them was changed to be a no-op when std is disabled.

(Closes #38)

@zesterer
Copy link
Owner

zesterer commented Jan 5, 2022

I think, as you mention in the post, that this might be the wrong way to go about it. Cargo features are strictly additive, and so there should be an std feature as part of the default-features list instead. This should also solve the issue you encountered with hashbrown, I believe.

What do you think about this?

@wackbyte
Copy link
Contributor Author

wackbyte commented Jan 5, 2022

I did use a std feature and added it to default-features, but the issue is that I can't enable an optional dependency if a feature is disabled.

@zesterer
Copy link
Owner

zesterer commented Jan 5, 2022

This might require hashbrown being non-optional in this case, which is a shame. I'd prefer that over a 'negative' feature flag though, I think.

@zesterer
Copy link
Owner

zesterer commented Feb 7, 2022

Hey, this has a few conflicts. Could you resolve them? Happy to merge after that.

@zesterer
Copy link
Owner

zesterer commented Feb 8, 2022

Thanks very much! I'll probably try to find time to add a no_std target to the CI tomorrow (some nebulous embedded ARM platform will do) so we can make sure that nothing that relies on std accidentally sneaks in without the appropriate flag.

@zesterer zesterer merged commit 64b10e2 into zesterer:master Feb 8, 2022
@mainrs
Copy link

mainrs commented Feb 8, 2022

Glad you could work it out @wackbyte. I didn't get the hasher to compile properly. Your ahash feature and implementation was missing in my PoC.

I should have updated the issue with my progress and problem though, maybe it could have been solved that way!
Thanks for the PR. chumksy on wasm is something I have been looking forward to!

@zesterer
Copy link
Owner

zesterer commented Feb 8, 2022

Great to hear that the library fits this use-case. I'm interested to hear how it works out!

@wackbyte wackbyte deleted the no-std branch March 13, 2022 17:32
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.

no_std support
3 participants