Amanieu / cstr_core

Implementation of CStr and CString for no_std environments
Apache License 2.0
41 stars 17 forks source link

Make CStr::from_bytes_with_nul_unchecked a constant function #14

Closed notgull closed 4 years ago

notgull commented 4 years ago

It would be nice if I were able to initialize CStr's in a constant context. The standard library equivalent has this functionality, and it doesn't seem like the implementation here is different from that. If there if interest, I am willing to implement a pull request for this feature.

Amanieu commented 4 years ago

I am happy to accept a PR for this!

notgull commented 4 years ago

A minor issue: const pointer dereferencing requires the #![feature(const_raw_ptr_deref)] feature gate. In order to get around this, I propose adding a new feature gate to cstr_core, to the tune of const_unsafe_new. When this feature is enabled; from_bytes_with_nul_unchecked will be const; otherwise, it will not be. Enabling this feature would require a nightly compiler. I would like to know if this is an acceptable API change.

Amanieu commented 4 years ago

That sounds good to me. Traditionally I've used the "nightly" feature name for things like this.