Repository: BurntSushi/byteorder (language: rust)

Issue:
`ByteOrder` examples have unnecessary `cfg!`
For example,
```rust
if cfg!(target_endian = "little") {
    assert_eq!(numbers, [5u32.swap_bytes(), 65000u32.swap_bytes()]);
} else {
    assert_eq!(numbers, [5, 65000]);
}
```
could be rewritten as
```rust
assert_eq!(numbers, [5u32.to_be(), 65000u32.to_be()]);
```


Discussion / hints:

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index a1de738..eb20a81 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1442,11 +1442,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_u16(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5u16.swap_bytes(), 65000u16.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5u16.to_be(), 65000u16.to_be()]);
     /// ```
     fn from_slice_u16(numbers: &mut [u16]);
 
@@ -1465,11 +1461,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_u32(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5u32.swap_bytes(), 65000u32.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5u32.to_be(), 65000u32.to_be()]);
     /// ```
     fn from_slice_u32(numbers: &mut [u32]);
 
@@ -1488,11 +1480,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_u64(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5u64.swap_bytes(), 65000u64.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5u64.to_be(), 65000u64.to_be()]);
     /// ```
     fn from_slice_u64(numbers: &mut [u64]);
 
@@ -1513,11 +1501,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_u128(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5u128.swap_bytes(), 65000u128.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5u128.to_be(), 65000u128.to_be()]);
     /// ```
     #[cfg(feature = "i128")]
     fn from_slice_u128(numbers: &mut [u128]);
@@ -1537,11 +1521,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_i16(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5i16.swap_bytes(), 65000i16.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5i16.to_be(), 65000i16.to_be()]);
     /// ```
     #[inline]
     fn from_slice_i16(src: &mut [i16]) {
@@ -1566,11 +1546,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_i32(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5i32.swap_bytes(), 65000i32.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5i32.to_be(), 65000i32.to_be()]);
     /// ```
     #[inline]
     fn from_slice_i32(src: &mut [i32]) {
@@ -1595,11 +1571,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_i64(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5i64.swap_bytes(), 65000i64.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5i64.to_be(), 65000i64.to_be()]);
     /// ```
     #[inline]
     fn from_slice_i64(src: &mut [i64]) {
@@ -1626,11 +1598,7 @@ pub trait ByteOrder
     ///
     /// let mut numbers = [5, 65000];
     /// BigEndian::from_slice_i128(&mut numbers);
-    /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(numbers, [5i128.swap_bytes(), 65000i128.swap_bytes()]);
-    /// } else {
-    ///     assert_eq!(numbers, [5, 65000]);
-    /// }
+    /// assert_eq!(numbers, [5i128.to_be(), 65000i128.to_be()]);
     /// ```
     #[cfg(feature = "i128")]
     #[inline]


Test patch: