Allow for static CStr

This commit is contained in:
Jeremy Soller
2019-01-06 14:40:01 -07:00
parent dc4aa9cf0b
commit c41c20a943
3 changed files with 5 additions and 3 deletions
+1 -1
View File
@@ -995,7 +995,7 @@ impl CStr {
/// }
/// ```
#[inline]
pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
&*(bytes as *const [u8] as *const CStr)
}
+2
View File
@@ -5,6 +5,8 @@
#![feature(alloc)]
#![feature(allocator_api)]
#![feature(const_fn)]
#![feature(const_raw_ptr_deref)]
#![feature(const_str_as_bytes)]
#![feature(const_vec_new)]
#![feature(core_intrinsics)]
#![feature(global_asm)]
+2 -2
View File
@@ -3,8 +3,8 @@ macro_rules! c_str {
($lit:expr) => {
#[allow(unused_unsafe)]
unsafe {
$crate::c_str::CStr::from_ptr(
concat!($lit, "\0").as_ptr() as *const $crate::platform::types::c_char
$crate::c_str::CStr::from_bytes_with_nul_unchecked(
concat!($lit, "\0").as_bytes()
)
}
};