SoftbearStudios / bitcode

A binary encoder/decoder for Rust
https://crates.io/crates/bitcode/
MIT License
376 stars 19 forks source link

Support using without `alloc` #31

Open katyo opened 3 months ago

katyo commented 3 months ago

I try this awesome library to create firmware for microcontrollers. Because it supports no_std I expected it works but seems currently Encoder and Decoder implementations uses Vec type from std/alloc. I got the following errors:

error[E0412]: cannot find type `Vec` in this scope

I added dependency as follows:

[dependencies.bitcode]
version = "0.6"
default-features = false
features = ["derive"]

Is it possible to use this crate without std and alloc at all?

finnbear commented 3 months ago

bitcode needs alloc (see the README)

Dropping the alloc dependency would require some redesigning and refactoring, and would probably add complexity. You're welcome to try writing a PR to do it (I'd be interested to see how far you can get). I anticipate you would need to use a lot of stack-allocated, fixed-sized vectors that abort instead of growing.