Skip to content

Commit b8f5090

Browse files
committed
Rewrote documentation for parse_bytes and to_str_bytes in {int, uint}_macros.rs
1 parent 3ffe56c commit b8f5090

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/libstd/num/int_macros.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,15 @@ impl Primitive for $T {}
234234

235235
// String conversion functions and impl str -> num
236236

237-
/// Parse a byte slice as a number in the given base.
237+
/// Parse a byte slice as a number in the given base
238238
///
239239
/// Yields an `Option` because `buf` may or may not actually be parseable.
240240
///
241241
/// # Examples
242242
///
243-
/// ```rust
244-
/// let digits = [49,50,51,52,53,54,55,56,57];
245-
/// let base = 10;
246-
/// let num = std::i64::parse_bytes(digits, base);
243+
/// ```
244+
/// let num = std::i64::parse_bytes([49,50,51,52,53,54,55,56,57], 10);
245+
/// assert!(num == Some(123456789));
247246
/// ```
248247
#[inline]
249248
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
@@ -270,6 +269,16 @@ impl FromStrRadix for $T {
270269
// String conversion functions and impl num -> str
271270

272271
/// Convert to a string as a byte slice in a given base.
272+
///
273+
/// Use in place of x.to_str() when you do not need to store the string permanently
274+
///
275+
/// # Examples
276+
///
277+
/// ```
278+
/// std::int::to_str_bytes(123, 10, |v| {
279+
/// assert!(v == "123".as_bytes());
280+
/// });
281+
/// ```
273282
#[inline]
274283
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
275284
// The radix can be as low as 2, so we need at least 64 characters for a

src/libstd/num/uint_macros.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,15 @@ impl Int for $T {}
148148

149149
// String conversion functions and impl str -> num
150150

151-
/// Parse a byte slice as a number in the given base.
151+
/// Parse a byte slice as a number in the given base
152152
///
153153
/// Yields an `Option` because `buf` may or may not actually be parseable.
154154
///
155155
/// # Examples
156156
///
157-
/// ```rust
158-
/// let digits = [49,50,51,52,53,54,55,56,57];
159-
/// let base = 10;
160-
/// let num = std::i64::parse_bytes(digits, base);
157+
/// ```
158+
/// let num = std::uint::parse_bytes([49,50,51,52,53,54,55,56,57], 10);
159+
/// assert!(num == Some(123456789));
161160
/// ```
162161
#[inline]
163162
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
@@ -184,6 +183,16 @@ impl FromStrRadix for $T {
184183
// String conversion functions and impl num -> str
185184

186185
/// Convert to a string as a byte slice in a given base.
186+
///
187+
/// Use in place of x.to_str() when you do not need to store the string permanently
188+
///
189+
/// # Examples
190+
///
191+
/// ```
192+
/// std::uint::to_str_bytes(123, 10, |v| {
193+
/// assert!(v == "123".as_bytes());
194+
/// });
195+
/// ```
187196
#[inline]
188197
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
189198
// The radix can be as low as 2, so we need at least 64 characters for a

0 commit comments

Comments
 (0)