Implement to native endian functions as a trait for u32/u64
This commit is contained in:
1 parent
6119408e1f
commit
62bd482acb
3 files changed
+31
-13
No files matched your search
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user