Skip to content

Commit cb8ca2d

Browse files
brendanzabalexcrichton
authored andcommitted
Shorten endian conversion method names
The consensus on rust-lang#14917 was that the proposed names were too long.
1 parent 779ca97 commit cb8ca2d

File tree

9 files changed

+84
-84
lines changed

9 files changed

+84
-84
lines changed

src/libcollections/hash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ macro_rules! impl_hash {
104104
#[inline]
105105
fn hash(&self, state: &mut S) {
106106
let a: [u8, ..::core::$ty::BYTES] = unsafe {
107-
mem::transmute((*self as $uty).to_little_endian() as $ty)
107+
mem::transmute((*self as $uty).to_le() as $ty)
108108
};
109109
state.write(a.as_slice())
110110
}

src/libcore/mem.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,85 +173,85 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) {
173173
///
174174
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
175175
#[inline]
176-
#[deprecated = "use `Int::to_little_endian` instead"]
177-
pub fn to_le16(x: u16) -> u16 { x.to_little_endian() }
176+
#[deprecated = "use `Int::to_le` instead"]
177+
pub fn to_le16(x: u16) -> u16 { x.to_le() }
178178

179179
/// Convert an u32 to little endian from the target's endianness.
180180
///
181181
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
182182
#[inline]
183-
#[deprecated = "use `Int::to_little_endian` instead"]
184-
pub fn to_le32(x: u32) -> u32 { x.to_little_endian() }
183+
#[deprecated = "use `Int::to_le` instead"]
184+
pub fn to_le32(x: u32) -> u32 { x.to_le() }
185185

186186
/// Convert an u64 to little endian from the target's endianness.
187187
///
188188
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
189189
#[inline]
190-
#[deprecated = "use `Int::to_little_endian` instead"]
191-
pub fn to_le64(x: u64) -> u64 { x.to_little_endian() }
190+
#[deprecated = "use `Int::to_le` instead"]
191+
pub fn to_le64(x: u64) -> u64 { x.to_le() }
192192

193193
/// Convert an u16 to big endian from the target's endianness.
194194
///
195195
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
196196
#[inline]
197-
#[deprecated = "use `Int::to_big_endian` instead"]
198-
pub fn to_be16(x: u16) -> u16 { x.to_big_endian() }
197+
#[deprecated = "use `Int::to_be` instead"]
198+
pub fn to_be16(x: u16) -> u16 { x.to_be() }
199199

200200
/// Convert an u32 to big endian from the target's endianness.
201201
///
202202
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
203203
#[inline]
204-
#[deprecated = "use `Int::to_big_endian` instead"]
205-
pub fn to_be32(x: u32) -> u32 { x.to_big_endian() }
204+
#[deprecated = "use `Int::to_be` instead"]
205+
pub fn to_be32(x: u32) -> u32 { x.to_be() }
206206

207207
/// Convert an u64 to big endian from the target's endianness.
208208
///
209209
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
210210
#[inline]
211-
#[deprecated = "use `Int::to_big_endian` instead"]
212-
pub fn to_be64(x: u64) -> u64 { x.to_big_endian() }
211+
#[deprecated = "use `Int::to_be` instead"]
212+
pub fn to_be64(x: u64) -> u64 { x.to_be() }
213213

214214
/// Convert an u16 from little endian to the target's endianness.
215215
///
216216
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
217217
#[inline]
218-
#[deprecated = "use `Int::from_little_endian` instead"]
219-
pub fn from_le16(x: u16) -> u16 { Int::from_little_endian(x) }
218+
#[deprecated = "use `Int::from_le` instead"]
219+
pub fn from_le16(x: u16) -> u16 { Int::from_le(x) }
220220

221221
/// Convert an u32 from little endian to the target's endianness.
222222
///
223223
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
224224
#[inline]
225-
#[deprecated = "use `Int::from_little_endian` instead"]
226-
pub fn from_le32(x: u32) -> u32 { Int::from_little_endian(x) }
225+
#[deprecated = "use `Int::from_le` instead"]
226+
pub fn from_le32(x: u32) -> u32 { Int::from_le(x) }
227227

228228
/// Convert an u64 from little endian to the target's endianness.
229229
///
230230
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
231231
#[inline]
232-
#[deprecated = "use `Int::from_little_endian` instead"]
233-
pub fn from_le64(x: u64) -> u64 { Int::from_little_endian(x) }
232+
#[deprecated = "use `Int::from_le` instead"]
233+
pub fn from_le64(x: u64) -> u64 { Int::from_le(x) }
234234

235235
/// Convert an u16 from big endian to the target's endianness.
236236
///
237237
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
238238
#[inline]
239-
#[deprecated = "use `Int::from_big_endian` instead"]
240-
pub fn from_be16(x: u16) -> u16 { Int::from_big_endian(x) }
239+
#[deprecated = "use `Int::from_be` instead"]
240+
pub fn from_be16(x: u16) -> u16 { Int::from_be(x) }
241241

242242
/// Convert an u32 from big endian to the target's endianness.
243243
///
244244
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
245245
#[inline]
246-
#[deprecated = "use `Int::from_big_endian` instead"]
247-
pub fn from_be32(x: u32) -> u32 { Int::from_big_endian(x) }
246+
#[deprecated = "use `Int::from_be` instead"]
247+
pub fn from_be32(x: u32) -> u32 { Int::from_be(x) }
248248

249249
/// Convert an u64 from big endian to the target's endianness.
250250
///
251251
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
252252
#[inline]
253-
#[deprecated = "use `Int::from_big_endian` instead"]
254-
pub fn from_be64(x: u64) -> u64 { Int::from_big_endian(x) }
253+
#[deprecated = "use `Int::from_be` instead"]
254+
pub fn from_be64(x: u64) -> u64 { Int::from_be(x) }
255255

256256
/// Swap the values at two mutable locations of the same type, without
257257
/// deinitialising or copying either one.

src/libcore/num/int_macros.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,25 @@ mod tests {
147147
}
148148

149149
#[test]
150-
fn test_little_endian() {
151-
assert_eq!(Int::from_little_endian(A.to_little_endian()), A);
152-
assert_eq!(Int::from_little_endian(B.to_little_endian()), B);
153-
assert_eq!(Int::from_little_endian(C.to_little_endian()), C);
154-
assert_eq!(Int::from_little_endian(_0), _0);
155-
assert_eq!(Int::from_little_endian(_1), _1);
156-
assert_eq!(_0.to_little_endian(), _0);
157-
assert_eq!(_1.to_little_endian(), _1);
150+
fn test_le() {
151+
assert_eq!(Int::from_le(A.to_le()), A);
152+
assert_eq!(Int::from_le(B.to_le()), B);
153+
assert_eq!(Int::from_le(C.to_le()), C);
154+
assert_eq!(Int::from_le(_0), _0);
155+
assert_eq!(Int::from_le(_1), _1);
156+
assert_eq!(_0.to_le(), _0);
157+
assert_eq!(_1.to_le(), _1);
158158
}
159159

160160
#[test]
161-
fn test_big_endian() {
162-
assert_eq!(Int::from_big_endian(A.to_big_endian()), A);
163-
assert_eq!(Int::from_big_endian(B.to_big_endian()), B);
164-
assert_eq!(Int::from_big_endian(C.to_big_endian()), C);
165-
assert_eq!(Int::from_big_endian(_0), _0);
166-
assert_eq!(Int::from_big_endian(_1), _1);
167-
assert_eq!(_0.to_big_endian(), _0);
168-
assert_eq!(_1.to_big_endian(), _1);
161+
fn test_be() {
162+
assert_eq!(Int::from_be(A.to_be()), A);
163+
assert_eq!(Int::from_be(B.to_be()), B);
164+
assert_eq!(Int::from_be(C.to_be()), C);
165+
assert_eq!(Int::from_be(_0), _0);
166+
assert_eq!(Int::from_be(_1), _1);
167+
assert_eq!(_0.to_be(), _0);
168+
assert_eq!(_1.to_be(), _1);
169169
}
170170

171171
#[test]

src/libcore/num/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,13 @@ pub trait Int: Primitive
498498
/// let n = 0x0123456789ABCDEFu64;
499499
///
500500
/// if cfg!(target_endian = "big") {
501-
/// assert_eq!(Int::from_big_endian(n), n)
501+
/// assert_eq!(Int::from_be(n), n)
502502
/// } else {
503-
/// assert_eq!(Int::from_big_endian(n), n.swap_bytes())
503+
/// assert_eq!(Int::from_be(n), n.swap_bytes())
504504
/// }
505505
/// ```
506506
#[inline]
507-
fn from_big_endian(x: Self) -> Self {
507+
fn from_be(x: Self) -> Self {
508508
if cfg!(target_endian = "big") { x } else { x.swap_bytes() }
509509
}
510510

@@ -518,13 +518,13 @@ pub trait Int: Primitive
518518
/// let n = 0x0123456789ABCDEFu64;
519519
///
520520
/// if cfg!(target_endian = "little") {
521-
/// assert_eq!(Int::from_little_endian(n), n)
521+
/// assert_eq!(Int::from_le(n), n)
522522
/// } else {
523-
/// assert_eq!(Int::from_little_endian(n), n.swap_bytes())
523+
/// assert_eq!(Int::from_le(n), n.swap_bytes())
524524
/// }
525525
/// ```
526526
#[inline]
527-
fn from_little_endian(x: Self) -> Self {
527+
fn from_le(x: Self) -> Self {
528528
if cfg!(target_endian = "little") { x } else { x.swap_bytes() }
529529
}
530530

@@ -538,13 +538,13 @@ pub trait Int: Primitive
538538
/// let n = 0x0123456789ABCDEFu64;
539539
///
540540
/// if cfg!(target_endian = "big") {
541-
/// assert_eq!(n.to_big_endian(), n)
541+
/// assert_eq!(n.to_be(), n)
542542
/// } else {
543-
/// assert_eq!(n.to_big_endian(), n.swap_bytes())
543+
/// assert_eq!(n.to_be(), n.swap_bytes())
544544
/// }
545545
/// ```
546546
#[inline]
547-
fn to_big_endian(self) -> Self {
547+
fn to_be(self) -> Self { // or not to be?
548548
if cfg!(target_endian = "big") { self } else { self.swap_bytes() }
549549
}
550550

@@ -558,13 +558,13 @@ pub trait Int: Primitive
558558
/// let n = 0x0123456789ABCDEFu64;
559559
///
560560
/// if cfg!(target_endian = "little") {
561-
/// assert_eq!(n.to_little_endian(), n)
561+
/// assert_eq!(n.to_le(), n)
562562
/// } else {
563-
/// assert_eq!(n.to_little_endian(), n.swap_bytes())
563+
/// assert_eq!(n.to_le(), n.swap_bytes())
564564
/// }
565565
/// ```
566566
#[inline]
567-
fn to_little_endian(self) -> Self {
567+
fn to_le(self) -> Self {
568568
if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
569569
}
570570
}

src/libcore/num/uint_macros.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,25 @@ mod tests {
9898
}
9999

100100
#[test]
101-
fn test_little_endian() {
102-
assert_eq!(Int::from_little_endian(A.to_little_endian()), A);
103-
assert_eq!(Int::from_little_endian(B.to_little_endian()), B);
104-
assert_eq!(Int::from_little_endian(C.to_little_endian()), C);
105-
assert_eq!(Int::from_little_endian(_0), _0);
106-
assert_eq!(Int::from_little_endian(_1), _1);
107-
assert_eq!(_0.to_little_endian(), _0);
108-
assert_eq!(_1.to_little_endian(), _1);
101+
fn test_le() {
102+
assert_eq!(Int::from_le(A.to_le()), A);
103+
assert_eq!(Int::from_le(B.to_le()), B);
104+
assert_eq!(Int::from_le(C.to_le()), C);
105+
assert_eq!(Int::from_le(_0), _0);
106+
assert_eq!(Int::from_le(_1), _1);
107+
assert_eq!(_0.to_le(), _0);
108+
assert_eq!(_1.to_le(), _1);
109109
}
110110

111111
#[test]
112-
fn test_big_endian() {
113-
assert_eq!(Int::from_big_endian(A.to_big_endian()), A);
114-
assert_eq!(Int::from_big_endian(B.to_big_endian()), B);
115-
assert_eq!(Int::from_big_endian(C.to_big_endian()), C);
116-
assert_eq!(Int::from_big_endian(_0), _0);
117-
assert_eq!(Int::from_big_endian(_1), _1);
118-
assert_eq!(_0.to_big_endian(), _0);
119-
assert_eq!(_1.to_big_endian(), _1);
112+
fn test_be() {
113+
assert_eq!(Int::from_be(A.to_be()), A);
114+
assert_eq!(Int::from_be(B.to_be()), B);
115+
assert_eq!(Int::from_be(C.to_be()), C);
116+
assert_eq!(Int::from_be(_0), _0);
117+
assert_eq!(Int::from_be(_1), _1);
118+
assert_eq!(_0.to_be(), _0);
119+
assert_eq!(_1.to_be(), _1);
120120
}
121121

122122
#[test]

src/libnative/io/net.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ use super::util;
2727
#[cfg(unix)] pub type sock_t = super::file::fd_t;
2828

2929
pub fn htons(u: u16) -> u16 {
30-
u.to_big_endian()
30+
u.to_be()
3131
}
3232
pub fn ntohs(u: u16) -> u16 {
33-
Int::from_big_endian(u)
33+
Int::from_be(u)
3434
}
3535

3636
enum InAddr {
@@ -46,7 +46,7 @@ fn ip_to_inaddr(ip: rtio::IpAddr) -> InAddr {
4646
(c as u32 << 8) |
4747
(d as u32 << 0);
4848
InAddr(libc::in_addr {
49-
s_addr: Int::from_big_endian(ip)
49+
s_addr: Int::from_be(ip)
5050
})
5151
}
5252
rtio::Ipv6Addr(a, b, c, d, e, f, g, h) => {
@@ -180,7 +180,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
180180
let storage: &libc::sockaddr_in = unsafe {
181181
mem::transmute(storage)
182182
};
183-
let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
183+
let ip = (storage.sin_addr.s_addr as u32).to_be();
184184
let a = (ip >> 24) as u8;
185185
let b = (ip >> 16) as u8;
186186
let c = (ip >> 8) as u8;

src/librustuv/net.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use uvll;
3030
/// Generic functions related to dealing with sockaddr things
3131
////////////////////////////////////////////////////////////////////////////////
3232

33-
pub fn htons(u: u16) -> u16 { u.to_big_endian() }
34-
pub fn ntohs(u: u16) -> u16 { Int::from_big_endian(u) }
33+
pub fn htons(u: u16) -> u16 { u.to_be() }
34+
pub fn ntohs(u: u16) -> u16 { Int::from_be(u) }
3535

3636
pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
3737
len: uint) -> rtio::SocketAddr {
@@ -41,7 +41,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
4141
let storage: &libc::sockaddr_in = unsafe {
4242
mem::transmute(storage)
4343
};
44-
let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
44+
let ip = (storage.sin_addr.s_addr as u32).to_be();
4545
let a = (ip >> 24) as u8;
4646
let b = (ip >> 16) as u8;
4747
let c = (ip >> 8) as u8;
@@ -89,7 +89,7 @@ fn addr_to_sockaddr(addr: rtio::SocketAddr) -> (libc::sockaddr_storage, uint) {
8989
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
9090
(*storage).sin_port = htons(addr.port);
9191
(*storage).sin_addr = libc::in_addr {
92-
s_addr: Int::from_big_endian(ip),
92+
s_addr: Int::from_be(ip),
9393

9494
};
9595
mem::size_of::<libc::sockaddr_in>()

src/libserialize/ebml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub mod reader {
183183

184184
unsafe {
185185
let ptr = data.as_ptr().offset(start as int) as *u32;
186-
let val = Int::from_big_endian(*ptr);
186+
let val = Int::from_be(*ptr);
187187

188188
let i = (val >> 28u) as uint;
189189
let (shift, mask) = SHIFT_MASK_TABLE[i];

src/libuuid/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ impl Uuid {
217217
data4: [0, ..8]
218218
};
219219

220-
fields.data1 = d1.to_big_endian();
221-
fields.data2 = d2.to_big_endian();
222-
fields.data3 = d3.to_big_endian();
220+
fields.data1 = d1.to_be();
221+
fields.data2 = d2.to_be();
222+
fields.data3 = d3.to_be();
223223
slice::bytes::copy_memory(fields.data4, d4);
224224

225225
unsafe {
@@ -339,9 +339,9 @@ impl Uuid {
339339
unsafe {
340340
uf = transmute_copy(&self.bytes);
341341
}
342-
uf.data1 = uf.data1.to_big_endian();
343-
uf.data2 = uf.data2.to_big_endian();
344-
uf.data3 = uf.data3.to_big_endian();
342+
uf.data1 = uf.data1.to_be();
343+
uf.data2 = uf.data2.to_be();
344+
uf.data3 = uf.data3.to_be();
345345
let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
346346
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
347347
uf.data1,

0 commit comments

Comments
 (0)