fosskers / rs-versions

A library for parsing and comparing software version numbers.
https://crates.io/crates/versions
MIT License
25 stars 5 forks source link

Support for heap-avoiding instances #27

Open Enyium opened 3 weeks ago

Enyium commented 3 weeks ago

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).

fosskers commented 3 weeks ago

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