enarx / ciborium

CBOR utilities
Other
222 stars 54 forks source link

[Feature]: no-alloc as option for ciborium #90

Open chrysn opened 10 months ago

chrysn commented 10 months ago

Is there an existing issue for this?

Description

While some parts of the high-level ciborium crate by their nature require alloc (in particular, Value doesn't work without), most of it should manage well without.

It'd be great if structs with serde based serializations could be used on embedded targets where alloc is typically unavailable.

Acceptance Criteria

The encode_vec test works when replacing the Vec with a heapless::vec in a build configuration that does not use extern crate alloc.

The crate is added to the category no-std::no-alloc in its Cargo.toml.

Suggestions for a technical implementation

ciborium could introduce a crate feature alloc that is in the default set.

Then, parts of the library that depend on alloc are marked #[cfg(feature=alloc)].

As the crate is already no-std, the relevant parts should be trivially discoverable by grepping for alloc, and further grepping for the names of all types that get disabled without it.