Skip to content

Commit 62812f1

Browse files
committed
auto merge of #9386 : Geal/rust/base64-doc, r=alexcrichton
Standard is now uppercase in the base64 module, and from_base64 now returns a Result
2 parents 4fd7f85 + 0b4f052 commit 62812f1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/libextra/base64.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ impl<'self> ToBase64 for &'self [u8] {
6464
*
6565
* ```rust
6666
* extern mod extra;
67-
* use extra::base64::{ToBase64, standard};
67+
* use extra::base64::{ToBase64, STANDARD};
6868
*
6969
* fn main () {
70-
* let str = [52,32].to_base64(standard);
71-
* println!("{}", str);
70+
* let str = [52,32].to_base64(STANDARD);
71+
* println!("base 64 output: {}", str);
7272
* }
7373
* ```
7474
*/
@@ -172,16 +172,19 @@ impl<'self> FromBase64 for &'self str {
172172
*
173173
* ```rust
174174
* extern mod extra;
175-
* use extra::base64::{ToBase64, FromBase64, standard};
175+
* use extra::base64::{ToBase64, FromBase64, STANDARD};
176176
* use std::str;
177177
*
178178
* fn main () {
179-
* let hello_str = "Hello, World".to_base64(standard);
180-
* println!("{}", hello_str);
181-
* let bytes = hello_str.from_base64();
182-
* println!("{:?}", bytes);
183-
* let result_str = str::from_utf8(bytes);
184-
* println!("{}", result_str);
179+
* let hello_str = bytes!("Hello, World").to_base64(STANDARD);
180+
* println!("base64 output: {}", hello_str);
181+
* let res = hello_str.from_base64();
182+
* if res.is_ok() {
183+
* let optBytes = str::from_utf8_opt(res.unwrap());
184+
* if optBytes.is_some() {
185+
* println!("decoded from base64: {}", optBytes.unwrap());
186+
* }
187+
* }
185188
* }
186189
* ```
187190
*/

0 commit comments

Comments
 (0)