twitchyliquid64 / usbd-hid

MIT License
87 stars 37 forks source link

macros: convert to no_std #53

Closed rmsyn closed 1 year ago

rmsyn commented 1 year ago

Converts the macros crate to no_std. Avoids indirectly including std library in a no_std crate.

haata commented 1 year ago

Why is alloc needed? (It can cause issues with certain no_std usage)

rmsyn commented 1 year ago

Why is alloc needed? (It can cause issues with certain no_std usage)

The library uses containers and traits that require dynamic allocation (notably String and Vec). It's possible to make more changes to feature-gate the parts of the library that require dynamic allocation behind an alloc feature.

It might also be possible to convert the usage to heapless variants that have a static capacity at compile-time. Especially for report descriptors, where the max size is known (64 bytes), heapless variants should be a very easy replacement.

For this PR, I just did the most straight forward thing. If a user has a problem with alloc usage, I can't see how they ever got the std versions to work.

haata commented 1 year ago

I personally haven't had any issues with the macro crate and no_std. However, I enable the 'host_dep cargo feature: https://github.com/rust-lang/cargo/issues/7915 in my environments.

Please fix up the checks and this should be good.