Skip to content

Conversation

@lilith
Copy link

@lilith lilith commented Jan 18, 2026

Adds no_std + alloc support for embedded/WASM use cases.

Closes #2

Changes

  • Add #![cfg_attr(not(feature = "std"), no_std)] for conditional no_std
  • Use hashbrown::HashMap in no_std mode (std uses std::collections::HashMap)
  • Add num-traits with libm feature for f32 math methods in no_std
  • Replace std::archcore::arch for SIMD intrinsics
  • Replace std::cmp, std::fmt, std::hash, std::mem, std::slicecore::*
  • Use core::error::Error (stable since Rust 1.81)
  • Feature-gate num_traits::Float import for no_std only
  • Fix pre-existing collapsible_if clippy warnings in vpsearch.rs

Usage

# Default (std) - unchanged
quantizr = "1.4.3"

# no_std + alloc  
quantizr = { version = "1.4.3", default-features = false }

Testing

  • Builds on thumbv7em-none-eabihf (no_std target)
  • All existing tests pass
  • Clippy clean with -D warnings

- Add #![cfg_attr(not(feature = "std"), no_std)] for conditional no_std
- Replace std::collections::HashMap with hashbrown::HashMap in no_std mode
- Replace std::arch with core::arch for SIMD intrinsics
- Replace std::cmp, std::fmt, std::hash, std::mem, std::slice with core equivalents
- Add num-traits with libm feature for f32 math methods (sqrt, round, powf)
- Feature-gate num_traits::Float import for no_std only
- Use core::error::Error (now stable in core)
- Make "std" feature the default, with "capi" requiring "std"
- Fix collapsible_if clippy warnings in vpsearch.rs

Tested on thumbv7em-none-eabihf target.
@DarthSim
Copy link
Owner

Hey @lilith!

I'm up to add no_std support, yet I'm not ready to test it right now, as I'm fully loaded at the moment.

Here are some comments I can make after the first glance:

  1. The dependencies needed for the no_std mode should be optional. Not sure how to do this without an additional no_std feature though.
  2. I'd add a tiny module named something like no_std_compat that just includes things needed for no_std: alloc::vec::Vec, alloc::boxed::Box, num_traits::Float, etc. I'd include this module in every file:
#[cfg(not(feature = "std"))]
use crate::no_std_compat::*

Also, it's probably a good idea to use hashbrown::HashMap even in std mode. It should be faster than std::collections::HashMap, and we don't need cryptographic security in the histogram. But I need to benchmark it first.

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.

Interest in no_std + alloc support?

2 participants