Prechádzať zdrojové kódy

Allow for static CStr

Jeremy Soller 6 rokov pred
rodič
commit
c41c20a943
3 zmenil súbory, kde vykonal 5 pridanie a 3 odobranie
  1. 1 1
      src/c_str.rs
  2. 2 0
      src/lib.rs
  3. 2 2
      src/macros.rs

+ 1 - 1
src/c_str.rs

@@ -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 - 0
src/lib.rs

@@ -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
src/macros.rs

@@ -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()
             )
         }
     };