From db69feee1e7683b7db98f506b647c8488f563f27 Mon Sep 17 00:00:00 2001 From: Lukasz Anforowicz Date: Tue, 5 Sep 2023 12:34:39 -0700 Subject: [PATCH] Use safe, public APIs where possible to remove some `unsafe` blocks. (#206) --- src/checked.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/checked.rs b/src/checked.rs index a9c0e67..68f72a9 100644 --- a/src/checked.rs +++ b/src/checked.rs @@ -243,7 +243,7 @@ impl From for CheckedCastError { pub fn try_from_bytes( s: &[u8], ) -> Result<&T, CheckedCastError> { - let pod = unsafe { internal::try_from_bytes(s) }?; + let pod = crate::try_from_bytes(s)?; if ::is_valid_bit_pattern(pod) { Ok(unsafe { &*(pod as *const ::Bits as *const T) }) @@ -281,7 +281,7 @@ pub fn try_from_bytes_mut( pub fn try_pod_read_unaligned( bytes: &[u8], ) -> Result { - let pod = unsafe { internal::try_pod_read_unaligned(bytes) }?; + let pod = crate::try_pod_read_unaligned(bytes)?; if ::is_valid_bit_pattern(&pod) { Ok(unsafe { transmute!(pod) }) @@ -305,7 +305,7 @@ pub fn try_pod_read_unaligned( pub fn try_cast( a: A, ) -> Result { - let pod = unsafe { internal::try_cast(a) }?; + let pod = crate::try_cast(a)?; if ::is_valid_bit_pattern(&pod) { Ok(unsafe { transmute!(pod) }) @@ -325,7 +325,7 @@ pub fn try_cast( pub fn try_cast_ref( a: &A, ) -> Result<&B, CheckedCastError> { - let pod = unsafe { internal::try_cast_ref(a) }?; + let pod = crate::try_cast_ref(a)?; if ::is_valid_bit_pattern(pod) { Ok(unsafe { &*(pod as *const ::Bits as *const B) }) @@ -374,7 +374,7 @@ pub fn try_cast_mut< pub fn try_cast_slice( a: &[A], ) -> Result<&[B], CheckedCastError> { - let pod = unsafe { internal::try_cast_slice(a) }?; + let pod = crate::try_cast_slice(a)?; if pod.iter().all(|pod| ::is_valid_bit_pattern(pod)) { Ok(unsafe {