arrayvec icon indicating copy to clipboard operation
arrayvec copied to clipboard

Add convienient const helper(hidden behind a feature flag)

Open jon-zu opened this issue 2 months ago • 0 comments

This PR introduces:

  • add '_ lifetime to prevent newer compiler warnings
  • unsafe from_raw_parts functions for ArrayVec and ArrayString to allow users to workaround the current const-limitations introduced by the MSRV limit manually
  • new module const_helper providing convienient functions and macros such as array_str!, array_bstr!, str, bstr, example:
        const S_EMPTY: ArrayString<0> = array_str!("");
        assert_eq!(&S_EMPTY, "");

        const S_EMPTY_CAP5: ArrayString<5> = array_str!("", 5);
        assert_eq!(&S_EMPTY_CAP5, "");

        const S1: ArrayString<5> = array_str!("hello");
        assert_eq!(&S1, "hello");

        const S2: ArrayString<10> = array_str!("hello", 10);
        assert_eq!(&S2, "hello");

The const_helper module is hidden behind a non-default const_helper feature flag, which should be only enabled for MSRV 1.63.0 users. For me this solves the most common pain point with this crate not having functions to construct strings in const context and also allows users to write unsafe helper functions for construction in case that would be required. While still allowing for later version bumps of the MSRV with more constant functionality overall.

jon-zu avatar Oct 31 '25 14:10 jon-zu