lang: drop commented-out c_str! implementation variants
This was an old version of a const-fn compatible checked c_str implementation which was never enabled. When we get rust 1.72, `CStr::from_bytes_with_nul` becomes usable in const contexts. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
1d68cc33a3
commit
484f12f3aa
@ -109,31 +109,3 @@ macro_rules! c_str {
|
||||
unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($data, "\0").as_bytes()) }
|
||||
}};
|
||||
}
|
||||
|
||||
/*
|
||||
// With rust 1.56 we can enable the `c_str!()` macro for const fns:
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(unconditional_panic)]
|
||||
pub const fn illegal_c_string() {
|
||||
[][0]
|
||||
}
|
||||
|
||||
/// Assert that a static byte slice is a valid C string (has no zeros except at the very end),
|
||||
/// and return it as a `&'static CStr`.
|
||||
pub const fn checked_c_str(bytes: &'static [u8]) -> &'static std::ffi::CStr {
|
||||
let mut i = 0;
|
||||
while i < bytes.len() - 1 {
|
||||
if bytes[i] == 0 {
|
||||
illegal_c_string();
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
unsafe { std::mem::transmute::<_, &'static std::ffi::CStr>(bytes) }
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! c_str {
|
||||
($data:expr) => { $crate::checked_c_str(concat!($data, "\0")) };
|
||||
}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user