Optionally using the Allocation API

I'm implementing several different data structures that achieve the same thing in order to benchmark them against each other. Benchmarking time is fairly easy with criterion et al, but I'd also like to understand how memory allocation differs too. To do that, I'd quite like to use the Allocator APIs, which are unstable, but I'd rather have a variation of the crate which was stable.

Is it possible to optionally use the Allocator API?

I tried reading the Vec source code and then wrote...

pub struct CompressedOrderedHexastore<I, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global>

That gave me an error error[E0734]: stability attributes may not be used outside of the standard library.

You cannot do that on stable.

What you can do is gate it behind a feature flag, so that others can use the current version of your crate on stable, but opt in to your flag and use it on nightly if they need it.

So, you'd need this in your lib.rs: #![cfg_attr(feature = "trace_allocations", feature(allocator_api))] (or whatever else you want to name your feature). And you'd need to use this cfg on everything that requires that unstable feature.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.