use crate::traits::{StringFromBytesMut, StringToFromBytes};
impl StringToFromBytes for str {
#[cfg(feature = "safe")]
#[inline]
fn bytes_as_self(bytes: &[u8]) -> &Self {
str::from_utf8(bytes).expect("Invalid UTF-8")
}
#[cfg(not(feature = "safe"))]
#[inline]
fn bytes_as_self(bytes: &[u8]) -> &Self {
unsafe { str::from_utf8_unchecked(bytes) }
}
#[inline]
fn self_as_raw_bytes(&self) -> &[u8] {
self.as_bytes()
}
}
impl StringFromBytesMut for str {
#[cfg(feature = "safe")]
#[inline]
fn bytes_as_self_mut(bytes: &mut [u8]) -> &mut Self {
str::from_utf8_mut(bytes).expect("Invalid UTF-8")
}
#[cfg(not(feature = "safe"))]
#[inline]
fn bytes_as_self_mut(bytes: &mut [u8]) -> &mut Self {
unsafe { str::from_utf8_unchecked_mut(bytes) }
}
}