]> git.lizzy.rs Git - rust.git/commitdiff
Rewrote documentation for parse_bytes and to_str_bytes in {int, uint}_macros.rs
authorJacob Hegna <jacobhegna@gmail.com>
Sun, 27 Apr 2014 20:49:47 +0000 (15:49 -0500)
committerJacob Hegna <jacobhegna@gmail.com>
Sun, 27 Apr 2014 20:49:47 +0000 (15:49 -0500)
src/libstd/num/int_macros.rs
src/libstd/num/uint_macros.rs

index cacd8d0aef91ac391fd550beb199bc7b5283d4b0..c6a9924e4eca296399c1195f948b4dc222c9e064 100644 (file)
@@ -234,16 +234,15 @@ impl Primitive for $T {}
 
 // String conversion functions and impl str -> num
 
-/// Parse a byte slice as a number in the given base.
+/// Parse a byte slice as a number in the given base
 ///
 /// Yields an `Option` because `buf` may or may not actually be parseable.
 ///
 /// # Examples
 ///
-/// ```rust
-/// let digits = [49,50,51,52,53,54,55,56,57];
-/// let base   = 10;
-/// let num    = std::i64::parse_bytes(digits, base);
+/// ```
+/// let num = std::i64::parse_bytes([49,50,51,52,53,54,55,56,57], 10);
+/// assert!(num == Some(123456789));
 /// ```
 #[inline]
 pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
@@ -270,6 +269,16 @@ fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
 // String conversion functions and impl num -> str
 
 /// Convert to a string as a byte slice in a given base.
+///
+/// Use in place of x.to_str() when you do not need to store the string permanently
+///
+/// # Examples
+///
+/// ```
+/// std::int::to_str_bytes(123, 10, |v| {
+///     assert!(v == "123".as_bytes());
+/// });
+/// ```
 #[inline]
 pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
     // The radix can be as low as 2, so we need at least 64 characters for a
index 697390a00699c20271ad761bdea61eb36389692e..8acedb080c2c76f7cc38b30a116a44d714db90ba 100644 (file)
@@ -148,16 +148,15 @@ impl Int for $T {}
 
 // String conversion functions and impl str -> num
 
-/// Parse a byte slice as a number in the given base.
+/// Parse a byte slice as a number in the given base
 ///
 /// Yields an `Option` because `buf` may or may not actually be parseable.
 ///
 /// # Examples
 ///
-/// ```rust
-/// let digits = [49,50,51,52,53,54,55,56,57];
-/// let base   = 10;
-/// let num    = std::i64::parse_bytes(digits, base);
+/// ```
+/// let num = std::uint::parse_bytes([49,50,51,52,53,54,55,56,57], 10);
+/// assert!(num == Some(123456789));
 /// ```
 #[inline]
 pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
@@ -184,6 +183,16 @@ fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
 // String conversion functions and impl num -> str
 
 /// Convert to a string as a byte slice in a given base.
+///
+/// Use in place of x.to_str() when you do not need to store the string permanently
+///
+/// # Examples
+///
+/// ```
+/// std::uint::to_str_bytes(123, 10, |v| {
+///     assert!(v == "123".as_bytes());
+/// });
+/// ```
 #[inline]
 pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
     // The radix can be as low as 2, so we need at least 64 characters for a