Skip to content

Commit 27a0269

Browse files
committed
Add comments for the implementations of from_base64 and to_base64 for .
1 parent 2ec2d99 commit 27a0269

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/libstd/base64.rs

+34
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ static CHARS: [char, ..64] = [
2626
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
2727
];
2828

29+
/**
30+
* Turn a vector of `u8` bytes into a string representing them in base64.
31+
*
32+
* *Example*:
33+
*
34+
* ~~~~
35+
* extern mod std;
36+
* use std::base64::ToBase64;
37+
*
38+
* fn main () {
39+
* let str = [52,32].to_base64();
40+
* println(fmt!("%s", str));
41+
* }
42+
* ~~~~
43+
*/
2944
impl<'self> ToBase64 for &'self [u8] {
3045
fn to_base64(&self) -> ~str {
3146
let mut s = ~"";
@@ -102,6 +117,25 @@ pub trait FromBase64 {
102117
fn from_base64(&self) -> ~[u8];
103118
}
104119
120+
/**
121+
* Turn a vector of `u8`s representing characters
122+
* encoding byte values in base64 into the vector of `u8` byte values.
123+
*
124+
* *Example*:
125+
*
126+
* ~~~~
127+
* extern mod std;
128+
* use std::base64::ToBase64;
129+
* use std::base64::FromBase64;
130+
*
131+
* fn main () {
132+
* let str = [52,32].to_base64();
133+
* println(fmt!("%s", str));
134+
* let bytes = str.from_base64();
135+
* println(fmt!("%?",bytes));
136+
* }
137+
* ~~~~
138+
*/
105139
impl FromBase64 for ~[u8] {
106140
fn from_base64(&self) -> ~[u8] {
107141
if self.len() % 4u != 0u { fail!(~"invalid base64 length"); }

0 commit comments

Comments
 (0)