Skip to content

Commit 2ec2d99

Browse files
committed
add rustdoc comments with examples for the string versions of to_base64 and from_base64
1 parent 5f13e9c commit 2ec2d99

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/libstd/base64.rs

+45
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ impl<'self> ToBase64 for &'self [u8] {
7575
}
7676
}
7777
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+
*/
7895
impl<'self> ToBase64 for &'self str {
7996
fn to_base64(&self) -> ~str {
8097
str::to_bytes(*self).to_base64()
@@ -147,6 +164,34 @@ impl FromBase64 for ~[u8] {
147164
}
148165
}
149166
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+
*/
150195
impl FromBase64 for ~str {
151196
fn from_base64(&self) -> ~[u8] {
152197
str::to_bytes(*self).from_base64()

0 commit comments

Comments
 (0)