@@ -75,6 +75,23 @@ impl<'self> ToBase64 for &'self [u8] {
75
75
}
76
76
}
77
77
78
+ /**
79
+ * Convert any string (literal, `@`, `&`, `~`) to base64 encoding.
80
+ *
81
+ *
82
+ * *Example*:
83
+ *
84
+ * ~~~~
85
+ * extern mod std;
86
+ * use std::base64::ToBase64;
87
+ *
88
+ * fn main () {
89
+ * let str = " Hello , World ".to_base64();
90
+ * println(fmt!(" %s",str));
91
+ * }
92
+ * ~~~~
93
+ *
94
+ */
78
95
impl<'self> ToBase64 for &'self str {
79
96
fn to_base64(&self) -> ~str {
80
97
str::to_bytes(*self).to_base64()
@@ -147,6 +164,34 @@ impl FromBase64 for ~[u8] {
147
164
}
148
165
}
149
166
167
+ /**
168
+ * Convert any string (literal, `@`, `&`, `~`)
169
+ * that contains a base64 encoded value, to the byte values it encodes.
170
+ *
171
+ * You can use the `from_bytes` function in `core::str`
172
+ * to turn a `[u8]` into a string with characters corresponding to those values.
173
+ *
174
+ * *Example*:
175
+ *
176
+ * This is an example of going from a string literal to the base64 encoding
177
+ * and back to the same string.
178
+ *
179
+ * ~~~~
180
+ * extern mod std;
181
+ * use std::base64::ToBase64;
182
+ * use std::base64::FromBase64;
183
+ * use core::str;
184
+ *
185
+ * fn main () {
186
+ * let hello_str = " Hello , World ".to_base64();
187
+ * println(fmt!(" %s",hello_str));
188
+ * let bytes = hello_str.from_base64();
189
+ * println(fmt!(" %?",bytes));
190
+ * let result_str = str::from_bytes(bytes);
191
+ * println(fmt!(" %s",result_str));
192
+ * }
193
+ * ~~~~
194
+ */
150
195
impl FromBase64 for ~str {
151
196
fn from_base64(&self) -> ~[u8] {
152
197
str::to_bytes(*self).from_base64()
0 commit comments