Skip to content

Commit

Permalink
Assume has_int_to_from_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Feb 8, 2024
1 parent 531d965 commit 7212041
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ fn main() {

ac.emit_expression_cfg("1f64.total_cmp(&2f64)", "has_total_cmp"); // 1.62

ac.emit_expression_cfg("1u32.to_ne_bytes()", "has_int_to_from_bytes");
ac.emit_expression_cfg("3.14f64.to_ne_bytes()", "has_float_to_from_bytes");

autocfg::rerun_path("build.rs");
Expand Down
44 changes: 0 additions & 44 deletions src/ops/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use core::borrow::{Borrow, BorrowMut};
use core::cmp::{Eq, Ord, PartialEq, PartialOrd};
use core::fmt::Debug;
use core::hash::Hash;
#[cfg(not(has_int_to_from_bytes))]
use core::mem::transmute;

pub trait NumBytes:
Debug
Expand Down Expand Up @@ -236,7 +234,6 @@ macro_rules! float_to_from_bytes_impl {

macro_rules! int_to_from_bytes_impl {
($T:ty, $L:expr) => {
#[cfg(has_int_to_from_bytes)]
impl ToBytes for $T {
type Bytes = [u8; $L];

Expand All @@ -256,7 +253,6 @@ macro_rules! int_to_from_bytes_impl {
}
}

#[cfg(has_int_to_from_bytes)]
impl FromBytes for $T {
type Bytes = [u8; $L];

Expand All @@ -275,46 +271,6 @@ macro_rules! int_to_from_bytes_impl {
<$T>::from_ne_bytes(*bytes)
}
}

#[cfg(not(has_int_to_from_bytes))]
impl ToBytes for $T {
type Bytes = [u8; $L];

#[inline]
fn to_be_bytes(&self) -> Self::Bytes {
<$T as ToBytes>::to_ne_bytes(&<$T>::to_be(*self))
}

#[inline]
fn to_le_bytes(&self) -> Self::Bytes {
<$T as ToBytes>::to_ne_bytes(&<$T>::to_le(*self))
}

#[inline]
fn to_ne_bytes(&self) -> Self::Bytes {
unsafe { transmute(*self) }
}
}

#[cfg(not(has_int_to_from_bytes))]
impl FromBytes for $T {
type Bytes = [u8; $L];

#[inline]
fn from_be_bytes(bytes: &Self::Bytes) -> Self {
Self::from_be(<Self as FromBytes>::from_ne_bytes(bytes))
}

#[inline]
fn from_le_bytes(bytes: &Self::Bytes) -> Self {
Self::from_le(<Self as FromBytes>::from_ne_bytes(bytes))
}

#[inline]
fn from_ne_bytes(bytes: &Self::Bytes) -> Self {
unsafe { transmute(*bytes) }
}
}
};
}

Expand Down

0 comments on commit 7212041

Please sign in to comment.