rs-versions icon indicating copy to clipboard operation
rs-versions copied to clipboard

Support for heap-avoiding instances

Open Enyium opened this issue 1 year ago • 1 comments

It would be nice, if you could add a feature (or make it the default?) that replaces Vec with SmallVec and String with SmolStr. SmallVec should always be used with the most suitable stack capacity to avoid heap allocations in common cases (probably 3 in your Chunks type, e.g.).

This would then allow to add const fns to create new instances (requiring the smallvec crate's const_new feature):

if config.last_app_version < *APP_VERSION {
    // Catch up.
    if config.last_app_version < Version::from_major_minor_patch(1, 0, 5) {
        // User agreement was changed in v1.0.5.
        config.user_agreement_accepted = false;
    }

    if config.last_app_version < Version::from_major_minor_patch(1, 2, 0) {
        config.something_else = true;
    }

    // To be extended with even more version comparisons, as time goes on.
}

Your serde feature must carry forward to the newly used crates (same feature name).

Enyium avatar Oct 22 '24 19:10 Enyium

Thanks for the suggestion, I'll look into it.

fosskers avatar Oct 22 '24 20:10 fosskers