Implement to native endian functions as a trait for u32/u64

This commit is contained in:
Nils Andreas Svee committed 2022-10-13 18:52:13 +02:00
1 parent 6119408e1f
commit 62bd482acb
3 files changed
+31 -13

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
pub trait ToNativeEndian {
fn to_ne(self) -> Self;
}
impl ToNativeEndian for u32 {
#[cfg(target_endian = "big")]
fn to_ne(self) -> Self {
self.to_be()
}
#[cfg(target_endian = "little")]
fn to_ne(self) -> Self {
self.to_le()
}
}
impl ToNativeEndian for u64 {
#[cfg(target_endian = "big")]
fn to_ne(self) -> Self {
self.to_be()
}
#[cfg(target_endian = "little")]
fn to_ne(self) -> Self {
self.to_le()
}
}