]> git.lizzy.rs Git - rust.git/commitdiff
Shorten endian conversion method names
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>
Tue, 17 Jun 2014 22:47:31 +0000 (15:47 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 19 Jun 2014 00:01:34 +0000 (17:01 -0700)
The consensus on #14917 was that the proposed names were too long.

src/libcollections/hash/mod.rs
src/libcore/mem.rs
src/libcore/num/int_macros.rs
src/libcore/num/mod.rs
src/libcore/num/uint_macros.rs
src/libnative/io/net.rs
src/librustuv/net.rs
src/libserialize/ebml.rs
src/libuuid/lib.rs

index 07c768d0c79162fb13c3cfe1fa7a72929e64b0a9..a0c0c9f97357816edc7470a674a78e1fb82ba6fb 100644 (file)
@@ -104,7 +104,7 @@ impl<S: Writer> Hash<S> for $ty {
             #[inline]
             fn hash(&self, state: &mut S) {
                 let a: [u8, ..::core::$ty::BYTES] = unsafe {
-                    mem::transmute((*self as $uty).to_little_endian() as $ty)
+                    mem::transmute((*self as $uty).to_le() as $ty)
                 };
                 state.write(a.as_slice())
             }
index 1032b820b27514d5aa40f238571424eaf2ad6a37..5280ac0d64fb22c10eec5f9bd6ebae6235e90a9f 100644 (file)
@@ -173,85 +173,85 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) {
 ///
 /// On little endian, this is a no-op.  On big endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::to_little_endian` instead"]
-pub fn to_le16(x: u16) -> u16 { x.to_little_endian() }
+#[deprecated = "use `Int::to_le` instead"]
+pub fn to_le16(x: u16) -> u16 { x.to_le() }
 
 /// Convert an u32 to little endian from the target's endianness.
 ///
 /// On little endian, this is a no-op.  On big endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::to_little_endian` instead"]
-pub fn to_le32(x: u32) -> u32 { x.to_little_endian() }
+#[deprecated = "use `Int::to_le` instead"]
+pub fn to_le32(x: u32) -> u32 { x.to_le() }
 
 /// Convert an u64 to little endian from the target's endianness.
 ///
 /// On little endian, this is a no-op.  On big endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::to_little_endian` instead"]
-pub fn to_le64(x: u64) -> u64 { x.to_little_endian() }
+#[deprecated = "use `Int::to_le` instead"]
+pub fn to_le64(x: u64) -> u64 { x.to_le() }
 
 /// Convert an u16 to big endian from the target's endianness.
 ///
 /// On big endian, this is a no-op.  On little endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::to_big_endian` instead"]
-pub fn to_be16(x: u16) -> u16 { x.to_big_endian() }
+#[deprecated = "use `Int::to_be` instead"]
+pub fn to_be16(x: u16) -> u16 { x.to_be() }
 
 /// Convert an u32 to big endian from the target's endianness.
 ///
 /// On big endian, this is a no-op.  On little endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::to_big_endian` instead"]
-pub fn to_be32(x: u32) -> u32 { x.to_big_endian() }
+#[deprecated = "use `Int::to_be` instead"]
+pub fn to_be32(x: u32) -> u32 { x.to_be() }
 
 /// Convert an u64 to big endian from the target's endianness.
 ///
 /// On big endian, this is a no-op.  On little endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::to_big_endian` instead"]
-pub fn to_be64(x: u64) -> u64 { x.to_big_endian() }
+#[deprecated = "use `Int::to_be` instead"]
+pub fn to_be64(x: u64) -> u64 { x.to_be() }
 
 /// Convert an u16 from little endian to the target's endianness.
 ///
 /// On little endian, this is a no-op.  On big endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::from_little_endian` instead"]
-pub fn from_le16(x: u16) -> u16 { Int::from_little_endian(x) }
+#[deprecated = "use `Int::from_le` instead"]
+pub fn from_le16(x: u16) -> u16 { Int::from_le(x) }
 
 /// Convert an u32 from little endian to the target's endianness.
 ///
 /// On little endian, this is a no-op.  On big endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::from_little_endian` instead"]
-pub fn from_le32(x: u32) -> u32 { Int::from_little_endian(x) }
+#[deprecated = "use `Int::from_le` instead"]
+pub fn from_le32(x: u32) -> u32 { Int::from_le(x) }
 
 /// Convert an u64 from little endian to the target's endianness.
 ///
 /// On little endian, this is a no-op.  On big endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::from_little_endian` instead"]
-pub fn from_le64(x: u64) -> u64 { Int::from_little_endian(x) }
+#[deprecated = "use `Int::from_le` instead"]
+pub fn from_le64(x: u64) -> u64 { Int::from_le(x) }
 
 /// Convert an u16 from big endian to the target's endianness.
 ///
 /// On big endian, this is a no-op.  On little endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::from_big_endian` instead"]
-pub fn from_be16(x: u16) -> u16 { Int::from_big_endian(x) }
+#[deprecated = "use `Int::from_be` instead"]
+pub fn from_be16(x: u16) -> u16 { Int::from_be(x) }
 
 /// Convert an u32 from big endian to the target's endianness.
 ///
 /// On big endian, this is a no-op.  On little endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::from_big_endian` instead"]
-pub fn from_be32(x: u32) -> u32 { Int::from_big_endian(x) }
+#[deprecated = "use `Int::from_be` instead"]
+pub fn from_be32(x: u32) -> u32 { Int::from_be(x) }
 
 /// Convert an u64 from big endian to the target's endianness.
 ///
 /// On big endian, this is a no-op.  On little endian, the bytes are swapped.
 #[inline]
-#[deprecated = "use `Int::from_big_endian` instead"]
-pub fn from_be64(x: u64) -> u64 { Int::from_big_endian(x) }
+#[deprecated = "use `Int::from_be` instead"]
+pub fn from_be64(x: u64) -> u64 { Int::from_be(x) }
 
 /// Swap the values at two mutable locations of the same type, without
 /// deinitialising or copying either one.
index 84744b3f5d7019b657575490950d6dfd60fe914d..79734324706b26e08dcffc1cb16bcdf061791763 100644 (file)
@@ -147,25 +147,25 @@ fn test_swap_bytes() {
     }
 
     #[test]
-    fn test_little_endian() {
-        assert_eq!(Int::from_little_endian(A.to_little_endian()), A);
-        assert_eq!(Int::from_little_endian(B.to_little_endian()), B);
-        assert_eq!(Int::from_little_endian(C.to_little_endian()), C);
-        assert_eq!(Int::from_little_endian(_0), _0);
-        assert_eq!(Int::from_little_endian(_1), _1);
-        assert_eq!(_0.to_little_endian(), _0);
-        assert_eq!(_1.to_little_endian(), _1);
+    fn test_le() {
+        assert_eq!(Int::from_le(A.to_le()), A);
+        assert_eq!(Int::from_le(B.to_le()), B);
+        assert_eq!(Int::from_le(C.to_le()), C);
+        assert_eq!(Int::from_le(_0), _0);
+        assert_eq!(Int::from_le(_1), _1);
+        assert_eq!(_0.to_le(), _0);
+        assert_eq!(_1.to_le(), _1);
     }
 
     #[test]
-    fn test_big_endian() {
-        assert_eq!(Int::from_big_endian(A.to_big_endian()), A);
-        assert_eq!(Int::from_big_endian(B.to_big_endian()), B);
-        assert_eq!(Int::from_big_endian(C.to_big_endian()), C);
-        assert_eq!(Int::from_big_endian(_0), _0);
-        assert_eq!(Int::from_big_endian(_1), _1);
-        assert_eq!(_0.to_big_endian(), _0);
-        assert_eq!(_1.to_big_endian(), _1);
+    fn test_be() {
+        assert_eq!(Int::from_be(A.to_be()), A);
+        assert_eq!(Int::from_be(B.to_be()), B);
+        assert_eq!(Int::from_be(C.to_be()), C);
+        assert_eq!(Int::from_be(_0), _0);
+        assert_eq!(Int::from_be(_1), _1);
+        assert_eq!(_0.to_be(), _0);
+        assert_eq!(_1.to_be(), _1);
     }
 
     #[test]
index ed0c24e7fa00864f917bfc3a088cdb5ab754ed17..dd32a6da1063b5e661b5b6707cb13da9d771ec19 100644 (file)
@@ -498,13 +498,13 @@ fn count_zeros(self) -> Self {
     /// let n = 0x0123456789ABCDEFu64;
     ///
     /// if cfg!(target_endian = "big") {
-    ///     assert_eq!(Int::from_big_endian(n), n)
+    ///     assert_eq!(Int::from_be(n), n)
     /// } else {
-    ///     assert_eq!(Int::from_big_endian(n), n.swap_bytes())
+    ///     assert_eq!(Int::from_be(n), n.swap_bytes())
     /// }
     /// ```
     #[inline]
-    fn from_big_endian(x: Self) -> Self {
+    fn from_be(x: Self) -> Self {
         if cfg!(target_endian = "big") { x } else { x.swap_bytes() }
     }
 
@@ -518,13 +518,13 @@ fn from_big_endian(x: Self) -> Self {
     /// let n = 0x0123456789ABCDEFu64;
     ///
     /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(Int::from_little_endian(n), n)
+    ///     assert_eq!(Int::from_le(n), n)
     /// } else {
-    ///     assert_eq!(Int::from_little_endian(n), n.swap_bytes())
+    ///     assert_eq!(Int::from_le(n), n.swap_bytes())
     /// }
     /// ```
     #[inline]
-    fn from_little_endian(x: Self) -> Self {
+    fn from_le(x: Self) -> Self {
         if cfg!(target_endian = "little") { x } else { x.swap_bytes() }
     }
 
@@ -538,13 +538,13 @@ fn from_little_endian(x: Self) -> Self {
     /// let n = 0x0123456789ABCDEFu64;
     ///
     /// if cfg!(target_endian = "big") {
-    ///     assert_eq!(n.to_big_endian(), n)
+    ///     assert_eq!(n.to_be(), n)
     /// } else {
-    ///     assert_eq!(n.to_big_endian(), n.swap_bytes())
+    ///     assert_eq!(n.to_be(), n.swap_bytes())
     /// }
     /// ```
     #[inline]
-    fn to_big_endian(self) -> Self {
+    fn to_be(self) -> Self { // or not to be?
         if cfg!(target_endian = "big") { self } else { self.swap_bytes() }
     }
 
@@ -558,13 +558,13 @@ fn to_big_endian(self) -> Self {
     /// let n = 0x0123456789ABCDEFu64;
     ///
     /// if cfg!(target_endian = "little") {
-    ///     assert_eq!(n.to_little_endian(), n)
+    ///     assert_eq!(n.to_le(), n)
     /// } else {
-    ///     assert_eq!(n.to_little_endian(), n.swap_bytes())
+    ///     assert_eq!(n.to_le(), n.swap_bytes())
     /// }
     /// ```
     #[inline]
-    fn to_little_endian(self) -> Self {
+    fn to_le(self) -> Self {
         if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
     }
 }
index 1fe3c4cf1f1cf3d2b60e1eb0ad46fdaa5307e0a2..be1f960bcc3dffc50a8e0e1028d6bb94c82822df 100644 (file)
@@ -98,25 +98,25 @@ fn test_swap_bytes() {
     }
 
     #[test]
-    fn test_little_endian() {
-        assert_eq!(Int::from_little_endian(A.to_little_endian()), A);
-        assert_eq!(Int::from_little_endian(B.to_little_endian()), B);
-        assert_eq!(Int::from_little_endian(C.to_little_endian()), C);
-        assert_eq!(Int::from_little_endian(_0), _0);
-        assert_eq!(Int::from_little_endian(_1), _1);
-        assert_eq!(_0.to_little_endian(), _0);
-        assert_eq!(_1.to_little_endian(), _1);
+    fn test_le() {
+        assert_eq!(Int::from_le(A.to_le()), A);
+        assert_eq!(Int::from_le(B.to_le()), B);
+        assert_eq!(Int::from_le(C.to_le()), C);
+        assert_eq!(Int::from_le(_0), _0);
+        assert_eq!(Int::from_le(_1), _1);
+        assert_eq!(_0.to_le(), _0);
+        assert_eq!(_1.to_le(), _1);
     }
 
     #[test]
-    fn test_big_endian() {
-        assert_eq!(Int::from_big_endian(A.to_big_endian()), A);
-        assert_eq!(Int::from_big_endian(B.to_big_endian()), B);
-        assert_eq!(Int::from_big_endian(C.to_big_endian()), C);
-        assert_eq!(Int::from_big_endian(_0), _0);
-        assert_eq!(Int::from_big_endian(_1), _1);
-        assert_eq!(_0.to_big_endian(), _0);
-        assert_eq!(_1.to_big_endian(), _1);
+    fn test_be() {
+        assert_eq!(Int::from_be(A.to_be()), A);
+        assert_eq!(Int::from_be(B.to_be()), B);
+        assert_eq!(Int::from_be(C.to_be()), C);
+        assert_eq!(Int::from_be(_0), _0);
+        assert_eq!(Int::from_be(_1), _1);
+        assert_eq!(_0.to_be(), _0);
+        assert_eq!(_1.to_be(), _1);
     }
 
     #[test]
index 23fd607aafeef74b05bedb4b57c8704fecf605b3..5dfae8d9efe649b5221b176dad416371c3504952 100644 (file)
 #[cfg(unix)]    pub type sock_t = super::file::fd_t;
 
 pub fn htons(u: u16) -> u16 {
-    u.to_big_endian()
+    u.to_be()
 }
 pub fn ntohs(u: u16) -> u16 {
-    Int::from_big_endian(u)
+    Int::from_be(u)
 }
 
 enum InAddr {
@@ -46,7 +46,7 @@ fn ip_to_inaddr(ip: rtio::IpAddr) -> InAddr {
                      (c as u32 <<  8) |
                      (d as u32 <<  0);
             InAddr(libc::in_addr {
-                s_addr: Int::from_big_endian(ip)
+                s_addr: Int::from_be(ip)
             })
         }
         rtio::Ipv6Addr(a, b, c, d, e, f, g, h) => {
@@ -180,7 +180,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
             let storage: &libc::sockaddr_in = unsafe {
                 mem::transmute(storage)
             };
-            let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
+            let ip = (storage.sin_addr.s_addr as u32).to_be();
             let a = (ip >> 24) as u8;
             let b = (ip >> 16) as u8;
             let c = (ip >>  8) as u8;
index aa7fab2565d8cf6ae910ba88d8f5d47a759b219e..82693acb1e9dc9573698ad23540aec33b5ec76e1 100644 (file)
@@ -30,8 +30,8 @@
 /// Generic functions related to dealing with sockaddr things
 ////////////////////////////////////////////////////////////////////////////////
 
-pub fn htons(u: u16) -> u16 { u.to_big_endian() }
-pub fn ntohs(u: u16) -> u16 { Int::from_big_endian(u) }
+pub fn htons(u: u16) -> u16 { u.to_be() }
+pub fn ntohs(u: u16) -> u16 { Int::from_be(u) }
 
 pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
                         len: uint) -> rtio::SocketAddr {
@@ -41,7 +41,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
             let storage: &libc::sockaddr_in = unsafe {
                 mem::transmute(storage)
             };
-            let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
+            let ip = (storage.sin_addr.s_addr as u32).to_be();
             let a = (ip >> 24) as u8;
             let b = (ip >> 16) as u8;
             let c = (ip >>  8) as u8;
@@ -89,7 +89,7 @@ fn addr_to_sockaddr(addr: rtio::SocketAddr) -> (libc::sockaddr_storage, uint) {
                 (*storage).sin_family = libc::AF_INET as libc::sa_family_t;
                 (*storage).sin_port = htons(addr.port);
                 (*storage).sin_addr = libc::in_addr {
-                    s_addr: Int::from_big_endian(ip),
+                    s_addr: Int::from_be(ip),
 
                 };
                 mem::size_of::<libc::sockaddr_in>()
index 7d0c82fc9a2d5f7d8171f20c48ae625838d120a4..12c5a3493c17bcd1091f4f8fff583eb8f18ae508 100644 (file)
@@ -183,7 +183,7 @@ pub fn vuint_at(data: &[u8], start: uint) -> DecodeResult<Res> {
 
         unsafe {
             let ptr = data.as_ptr().offset(start as int) as *u32;
-            let val = Int::from_big_endian(*ptr);
+            let val = Int::from_be(*ptr);
 
             let i = (val >> 28u) as uint;
             let (shift, mask) = SHIFT_MASK_TABLE[i];
index bbd461e3dde0db3a4513b17dd2d0c134ce3f1a33..b68b435da4bb0a7d427504083e4586d6fa4a5fce 100644 (file)
@@ -217,9 +217,9 @@ pub fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8]) -> Uuid {
                 data4: [0, ..8]
         };
 
-        fields.data1 = d1.to_big_endian();
-        fields.data2 = d2.to_big_endian();
-        fields.data3 = d3.to_big_endian();
+        fields.data1 = d1.to_be();
+        fields.data2 = d2.to_be();
+        fields.data3 = d3.to_be();
         slice::bytes::copy_memory(fields.data4, d4);
 
         unsafe {
@@ -339,9 +339,9 @@ pub fn to_hyphenated_str(&self) -> String {
         unsafe {
             uf = transmute_copy(&self.bytes);
         }
-        uf.data1 = uf.data1.to_big_endian();
-        uf.data2 = uf.data2.to_big_endian();
-        uf.data3 = uf.data3.to_big_endian();
+        uf.data1 = uf.data1.to_be();
+        uf.data2 = uf.data2.to_be();
+        uf.data3 = uf.data3.to_be();
         let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
                          {:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
             uf.data1,