lloydmeta / frunk

Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.
https://beachape.com/frunk/
MIT License
1.28k stars 58 forks source link

rework #![no_std] support, switch on `alloc` #236

Closed mammothbane closed 2 months ago

mammothbane commented 3 months ago

Finally got around to change I brought up in #220. See also #233.

Most of the uses of std in the crate are of Vec, String, and Box, which are in alloc, which is available on #![no_std] via extern crate alloc;. This commit adjusts these uses to use alloc directly and adds an alloc feature flag to control them. The notable exceptions still requiring a std flag are HashMap and HashSet (I'm working on a separate change to add BTree{Map,Set} support for #![no_std] envs). frunk_core no longer needs a std flag: it has been marked deprecated with a comment.

The reimport of core as std (see #220 for historical explanation) is converted to direct usage of core everywhere.

Removed #[cfg(feature = "std")] condition from frunk_laws and made it depend on frunk/std -- it depends on quickcheck, which requires std.

Added #[cfg(test)] extern crate std; to #![no_std] crates, as std is required to run the libtest harness.

Tested against all the combinations of feature flags I could think of. Successfully compiles into a #![no_std] embedded project with alloc enabled.

lloydmeta commented 3 months ago

Thanks for this; I'll review more once I get a chance, but IIUC this should probably result in at least a minor version bump right?

mammothbane commented 3 months ago

Yeah, everything other than removing the frunk_core/std should be minor — everything's compatible. Removing frunk_core/std is major, but I can add have added it back and marked as deprecated.

lloydmeta commented 2 months ago

Thanks for this. Just cut a new release for this.