Skip to content

Commit 5026d11

Browse files
committed
Doc-sprint: Document endian conversion functions
1 parent 7156ded commit 5026d11

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

src/libstd/mem.rs

+95
Original file line numberDiff line numberDiff line change
@@ -99,32 +99,127 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) {
9999
intrinsics::move_val_init(dst, src)
100100
}
101101

102+
/// Convert an i16 to little endian from the target's endianness.
103+
///
104+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
102105
#[cfg(target_endian = "little")] #[inline] pub fn to_le16(x: i16) -> i16 { x }
106+
107+
/// Convert an i16 to little endian from the target's endianness.
108+
///
109+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
103110
#[cfg(target_endian = "big")] #[inline] pub fn to_le16(x: i16) -> i16 { unsafe { bswap16(x) } }
111+
112+
/// Convert an i32 to little endian from the target's endianness.
113+
///
114+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
104115
#[cfg(target_endian = "little")] #[inline] pub fn to_le32(x: i32) -> i32 { x }
116+
117+
/// Convert an i32 to little endian from the target's endianness.
118+
///
119+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
105120
#[cfg(target_endian = "big")] #[inline] pub fn to_le32(x: i32) -> i32 { unsafe { bswap32(x) } }
121+
122+
/// Convert an i64 to little endian from the target's endianness.
123+
///
124+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
106125
#[cfg(target_endian = "little")] #[inline] pub fn to_le64(x: i64) -> i64 { x }
126+
127+
/// Convert an i64 to little endian from the target's endianness.
128+
///
129+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
107130
#[cfg(target_endian = "big")] #[inline] pub fn to_le64(x: i64) -> i64 { unsafe { bswap64(x) } }
108131

132+
133+
/// Convert an i16 to big endian from the target's endianness.
134+
///
135+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
109136
#[cfg(target_endian = "little")] #[inline] pub fn to_be16(x: i16) -> i16 { unsafe { bswap16(x) } }
137+
138+
/// Convert an i16 to big endian from the target's endianness.
139+
///
140+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
110141
#[cfg(target_endian = "big")] #[inline] pub fn to_be16(x: i16) -> i16 { x }
142+
143+
/// Convert an i32 to big endian from the target's endianness.
144+
///
145+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
111146
#[cfg(target_endian = "little")] #[inline] pub fn to_be32(x: i32) -> i32 { unsafe { bswap32(x) } }
147+
148+
/// Convert an i32 to big endian from the target's endianness.
149+
///
150+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
112151
#[cfg(target_endian = "big")] #[inline] pub fn to_be32(x: i32) -> i32 { x }
152+
153+
/// Convert an i64 to big endian from the target's endianness.
154+
///
155+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
113156
#[cfg(target_endian = "little")] #[inline] pub fn to_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
157+
158+
/// Convert an i64 to big endian from the target's endianness.
159+
///
160+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
114161
#[cfg(target_endian = "big")] #[inline] pub fn to_be64(x: i64) -> i64 { x }
115162

163+
164+
/// Convert an i16 from little endian to the target's endianness.
165+
///
166+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
116167
#[cfg(target_endian = "little")] #[inline] pub fn from_le16(x: i16) -> i16 { x }
168+
169+
/// Convert an i16 from little endian to the target's endianness.
170+
///
171+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
117172
#[cfg(target_endian = "big")] #[inline] pub fn from_le16(x: i16) -> i16 { unsafe { bswap16(x) } }
173+
174+
/// Convert an i32 from little endian to the target's endianness.
175+
///
176+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
118177
#[cfg(target_endian = "little")] #[inline] pub fn from_le32(x: i32) -> i32 { x }
178+
179+
/// Convert an i32 from little endian to the target's endianness.
180+
///
181+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
119182
#[cfg(target_endian = "big")] #[inline] pub fn from_le32(x: i32) -> i32 { unsafe { bswap32(x) } }
183+
184+
/// Convert an i64 from little endian to the target's endianness.
185+
///
186+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
120187
#[cfg(target_endian = "little")] #[inline] pub fn from_le64(x: i64) -> i64 { x }
188+
189+
/// Convert an i64 from little endian to the target's endianness.
190+
///
191+
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
121192
#[cfg(target_endian = "big")] #[inline] pub fn from_le64(x: i64) -> i64 { unsafe { bswap64(x) } }
122193

194+
195+
/// Convert an i16 from big endian to the target's endianness.
196+
///
197+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
123198
#[cfg(target_endian = "little")] #[inline] pub fn from_be16(x: i16) -> i16 { unsafe { bswap16(x) } }
199+
200+
/// Convert an i16 from big endian to the target's endianness.
201+
///
202+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
124203
#[cfg(target_endian = "big")] #[inline] pub fn from_be16(x: i16) -> i16 { x }
204+
205+
/// Convert an i32 from big endian to the target's endianness.
206+
///
207+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
125208
#[cfg(target_endian = "little")] #[inline] pub fn from_be32(x: i32) -> i32 { unsafe { bswap32(x) } }
209+
210+
/// Convert an i32 from big endian to the target's endianness.
211+
///
212+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
126213
#[cfg(target_endian = "big")] #[inline] pub fn from_be32(x: i32) -> i32 { x }
214+
215+
/// Convert an i64 from big endian to the target's endianness.
216+
///
217+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
127218
#[cfg(target_endian = "little")] #[inline] pub fn from_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
219+
220+
/// Convert an i64 from big endian to the target's endianness.
221+
///
222+
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
128223
#[cfg(target_endian = "big")] #[inline] pub fn from_be64(x: i64) -> i64 { x }
129224

130225

0 commit comments

Comments
 (0)