From 5f4e15870513954d4a3c8b5099f26b42eecaaf28 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 7 Sep 2022 22:52:19 -0400 Subject: [PATCH] Temporarily revert use of core::ffi::CStr The move of `CStr` from `std` to `core` is not due to become stable until 1.64. The first nightly where it could be used without the unstable `core_c_str` feature was 2022-07-16, which is still pretty recent. Let's back this change out for now to give users pinned to older versions more time. --- CHANGELOG.md | 1 - src/data_types/strs.rs | 24 ------------------------ 2 files changed, 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0714d092c..43fc7f537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,6 @@ - Added `DiskIo` and `DiskIo2` protocols. - Added `HardDriveMediaDevicePath` and related types. - Added `PartialOrd` and `Ord` to the traits derived by `Guid`. -- Added `TryFrom` implementation for `CStr8`. ### Fixed diff --git a/src/data_types/strs.rs b/src/data_types/strs.rs index eaa9c55f2..888d0b97a 100644 --- a/src/data_types/strs.rs +++ b/src/data_types/strs.rs @@ -1,5 +1,4 @@ use super::chars::{Char16, Char8, NUL_16, NUL_8}; -use core::ffi::CStr; use core::fmt; use core::iter::Iterator; use core::marker::PhantomData; @@ -58,11 +57,6 @@ pub enum FromStrWithBufError { /// This type is largely inspired by [`core::ffi::CStr`] with the exception that all characters are /// guaranteed to be 8 bit long. /// -/// A [`CStr8`] can be constructed from a [`core::ffi::CStr`] via a `try_from` call: -/// ```ignore -/// let cstr8: &CStr8 = TryFrom::try_from(cstr).unwrap(); -/// ``` -/// /// For convenience, a [`CStr8`] is comparable with [`core::str`] and /// `alloc::string::String` from the standard library through the trait [`EqStrUntilNul`]. #[repr(transparent)] @@ -160,14 +154,6 @@ impl> EqStrUntilNul for CStr8 { } } -impl<'a> TryFrom<&'a CStr> for &'a CStr8 { - type Error = FromSliceWithNulError; - - fn try_from(cstr: &'a CStr) -> Result { - CStr8::from_bytes_with_nul(cstr.to_bytes_with_nul()) - } -} - /// An UCS-2 null-terminated string. /// /// This type is largely inspired by [`core::ffi::CStr`] with the exception that all characters are @@ -533,16 +519,6 @@ mod tests { use crate::alloc_api::string::String; use uefi_macros::{cstr16, cstr8}; - // Tests if our CStr8 type can be constructed from a valid core::ffi::CStr - #[test] - fn test_cstr8_from_cstr() { - let msg = "hello world\0"; - let cstr = unsafe { CStr::from_ptr(msg.as_ptr().cast()) }; - let cstr8: &CStr8 = TryFrom::try_from(cstr).unwrap(); - assert!(cstr8.eq_str_until_nul(&msg)); - assert!(msg.eq_str_until_nul(cstr8)); - } - #[test] fn test_cstr16_num_bytes() { let s = CStr16::from_u16_with_nul(&[65, 66, 67, 0]).unwrap();