diff options
| author | Leah Hanson <astrieanna@gmail.com> | 2013-04-12 09:41:07 -0400 |
|---|---|---|
| committer | Leah Hanson <astrieanna@gmail.com> | 2013-04-12 09:41:07 -0400 |
| commit | 2ec2d99bbd1a15a8f278b3cb82ddfa9ebafa96b3 (patch) | |
| tree | b39b68e28568e4151b0657d5ef2d6cecb621fe6e /src/libstd/base64.rs | |
| parent | 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346 (diff) | |
| download | rust-2ec2d99bbd1a15a8f278b3cb82ddfa9ebafa96b3.tar.gz rust-2ec2d99bbd1a15a8f278b3cb82ddfa9ebafa96b3.zip | |
add rustdoc comments with examples for the string versions of to_base64 and from_base64
Diffstat (limited to 'src/libstd/base64.rs')
| -rw-r--r-- | src/libstd/base64.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 0266f2d8631..0815e0ff0b5 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -75,6 +75,23 @@ impl<'self> ToBase64 for &'self [u8] { } } +/** + * Convert any string (literal, `@`, `&`, `~`) to base64 encoding. + * + * + * *Example*: + * + * ~~~~ + * extern mod std; + * use std::base64::ToBase64; + * + * fn main () { + * let str = "Hello, World".to_base64(); + * println(fmt!("%s",str)); + * } + * ~~~~ + * + */ impl<'self> ToBase64 for &'self str { fn to_base64(&self) -> ~str { str::to_bytes(*self).to_base64() @@ -147,6 +164,34 @@ impl FromBase64 for ~[u8] { } } +/** + * Convert any string (literal, `@`, `&`, `~`) + * that contains a base64 encoded value, to the byte values it encodes. + * + * You can use the `from_bytes` function in `core::str` + * to turn a `[u8]` into a string with characters corresponding to those values. + * + * *Example*: + * + * This is an example of going from a string literal to the base64 encoding + * and back to the same string. + * + * ~~~~ + * extern mod std; + * use std::base64::ToBase64; + * use std::base64::FromBase64; + * use core::str; + * + * fn main () { + * let hello_str = "Hello, World".to_base64(); + * println(fmt!("%s",hello_str)); + * let bytes = hello_str.from_base64(); + * println(fmt!("%?",bytes)); + * let result_str = str::from_bytes(bytes); + * println(fmt!("%s",result_str)); + * } + * ~~~~ + */ impl FromBase64 for ~str { fn from_base64(&self) -> ~[u8] { str::to_bytes(*self).from_base64() |
