From f38e4e6d97bf1691858d007afd36b1f356de4774 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 24 Nov 2014 20:06:06 -0500 Subject: /** -> /// This is considered good convention. --- src/libserialize/base64.rs | 82 ++++++++++++++++++++++------------------------ src/libserialize/hex.rs | 76 ++++++++++++++++++++---------------------- 2 files changed, 75 insertions(+), 83 deletions(-) (limited to 'src/libserialize') diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 41feee8257f..b7d8885a5f9 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -64,21 +64,19 @@ pub trait ToBase64 for Sized? { } impl ToBase64 for [u8] { - /** - * Turn a vector of `u8` bytes into a base64 string. - * - * # Example - * - * ```rust - * extern crate serialize; - * use serialize::base64::{ToBase64, STANDARD}; - * - * fn main () { - * let str = [52,32].to_base64(STANDARD); - * println!("base 64 output: {}", str); - * } - * ``` - */ + /// Turn a vector of `u8` bytes into a base64 string. + /// + /// # Example + /// + /// ```rust + /// extern crate serialize; + /// use serialize::base64::{ToBase64, STANDARD}; + /// + /// fn main () { + /// let str = [52,32].to_base64(STANDARD); + /// println!("base 64 output: {}", str); + /// } + /// ``` fn to_base64(&self, config: Config) -> String { let bytes = match config.char_set { Standard => STANDARD_CHARS, @@ -194,34 +192,32 @@ impl error::Error for FromBase64Error { } impl FromBase64 for str { - /** - * Convert any base64 encoded string (literal, `@`, `&`, or `~`) - * to the byte values it encodes. - * - * You can use the `String::from_utf8` function to turn a `Vec` into a - * string with characters corresponding to those values. - * - * # Example - * - * This converts a string literal to base64 and back. - * - * ```rust - * extern crate serialize; - * use serialize::base64::{ToBase64, FromBase64, STANDARD}; - * - * fn main () { - * let hello_str = b"Hello, World".to_base64(STANDARD); - * println!("base64 output: {}", hello_str); - * let res = hello_str.as_slice().from_base64(); - * if res.is_ok() { - * let opt_bytes = String::from_utf8(res.unwrap()); - * if opt_bytes.is_ok() { - * println!("decoded from base64: {}", opt_bytes.unwrap()); - * } - * } - * } - * ``` - */ + /// Convert any base64 encoded string (literal, `@`, `&`, or `~`) + /// to the byte values it encodes. + /// + /// You can use the `String::from_utf8` function to turn a `Vec` into a + /// string with characters corresponding to those values. + /// + /// # Example + /// + /// This converts a string literal to base64 and back. + /// + /// ```rust + /// extern crate serialize; + /// use serialize::base64::{ToBase64, FromBase64, STANDARD}; + /// + /// fn main () { + /// let hello_str = b"Hello, World".to_base64(STANDARD); + /// println!("base64 output: {}", hello_str); + /// let res = hello_str.as_slice().from_base64(); + /// if res.is_ok() { + /// let opt_bytes = String::from_utf8(res.unwrap()); + /// if opt_bytes.is_ok() { + /// println!("decoded from base64: {}", opt_bytes.unwrap()); + /// } + /// } + /// } + /// ``` #[inline] fn from_base64(&self) -> Result, FromBase64Error> { self.as_bytes().from_base64() diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 78859d6778d..2a3c410ba7c 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -27,21 +27,19 @@ pub trait ToHex for Sized? { static CHARS: &'static[u8] = b"0123456789abcdef"; impl ToHex for [u8] { - /** - * Turn a vector of `u8` bytes into a hexadecimal string. - * - * # Example - * - * ```rust - * extern crate serialize; - * use serialize::hex::ToHex; - * - * fn main () { - * let str = [52,32].to_hex(); - * println!("{}", str); - * } - * ``` - */ + /// Turn a vector of `u8` bytes into a hexadecimal string. + /// + /// # Example + /// + /// ```rust + /// extern crate serialize; + /// use serialize::hex::ToHex; + /// + /// fn main () { + /// let str = [52,32].to_hex(); + /// println!("{}", str); + /// } + /// ``` fn to_hex(&self) -> String { let mut v = Vec::with_capacity(self.len() * 2); for &byte in self.iter() { @@ -95,31 +93,29 @@ impl error::Error for FromHexError { impl FromHex for str { - /** - * Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`) - * to the byte values it encodes. - * - * You can use the `String::from_utf8` function to turn a - * `Vec` into a string with characters corresponding to those values. - * - * # Example - * - * This converts a string literal to hexadecimal and back. - * - * ```rust - * extern crate serialize; - * use serialize::hex::{FromHex, ToHex}; - * - * fn main () { - * let hello_str = "Hello, World".as_bytes().to_hex(); - * println!("{}", hello_str); - * let bytes = hello_str.as_slice().from_hex().unwrap(); - * println!("{}", bytes); - * let result_str = String::from_utf8(bytes).unwrap(); - * println!("{}", result_str); - * } - * ``` - */ + /// Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`) + /// to the byte values it encodes. + /// + /// You can use the `String::from_utf8` function to turn a + /// `Vec` into a string with characters corresponding to those values. + /// + /// # Example + /// + /// This converts a string literal to hexadecimal and back. + /// + /// ```rust + /// extern crate serialize; + /// use serialize::hex::{FromHex, ToHex}; + /// + /// fn main () { + /// let hello_str = "Hello, World".as_bytes().to_hex(); + /// println!("{}", hello_str); + /// let bytes = hello_str.as_slice().from_hex().unwrap(); + /// println!("{}", bytes); + /// let result_str = String::from_utf8(bytes).unwrap(); + /// println!("{}", result_str); + /// } + /// ``` fn from_hex(&self) -> Result, FromHexError> { // This may be an overestimate if there is any whitespace let mut b = Vec::with_capacity(self.len() / 2); -- cgit 1.4.1-3-g733a5