Skip to content

Nightly constify to_str (and everything on its path)#24

Merged
Amanieu merged 3 commits intoAmanieu:masterfrom
chrysn-pull-requests:to_str-const
Dec 21, 2021
Merged

Nightly constify to_str (and everything on its path)#24
Amanieu merged 3 commits intoAmanieu:masterfrom
chrysn-pull-requests:to_str-const

Conversation

@chrysn
Copy link
Contributor

@chrysn chrysn commented Dec 21, 2021

This constifies to_str in three progressive steps.

Two new features are enabled at nightly const_str_from_utf8 and const_slice_from_raw_parts. The former is rather new (but appears to be unproblematic), the latter has been around for over a year (and doesn't look troublesome either).

Two functions (to_str, to_bytes_with_nul) are constified without actual code changes; to_bytes needs code changes for nightly (it builds the slice through unsafe from_parts rather than slicing). If the former are too much duplication, it'd be an option to pull in const_ft to let preprocessor do it, similar to how Rust itself uses rustc_const_unstable. (Might actually not be a dependency but copied in, because it's using a hardcoded feature name that is not "nighlty").

As is currently being done in other functions, this duplicates the
function and adds the `const` keyword.
This requires a slightly different implementation that goes through
unsafe from_parts, as slicing is not available in a const fashion yet.
As is currently being done in other functions, this duplicates the
function and adds the `const` keyword.
@Amanieu
Copy link
Owner

Amanieu commented Dec 21, 2021

LGTM!

@Amanieu Amanieu merged commit 0aa2a66 into Amanieu:master Dec 21, 2021
@Amanieu
Copy link
Owner

Amanieu commented Dec 21, 2021

Do you want me to publish a new release now or do you have other changes planned?

@chrysn chrysn deleted the to_str-const branch December 22, 2021 13:24
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.

2 participants