pub trait FromBase64 {
// Required method
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>;
}Expand description
A trait for converting from base64 encoded values.
Required Methods§
Sourcefn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>
Converts the value of self, interpreted as base64 encoded data, into
an owned vector of bytes, returning the vector.
Implementations on Foreign Types§
Source§impl FromBase64 for str
impl FromBase64 for str
Source§fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>
Convert any base64 encoded string (literal, @, &, or ~)
to the byte values it encodes.
You can use the String::from_utf8 function to turn a Vec<u8> into a
string with characters corresponding to those values.
§Example
This converts a string literal to base64 and back.
extern crate rustc_serialize;
use rustc_serialize::base64::{ToBase64, FromBase64, STANDARD};
fn main () {
let hello_str = b"Hello, World".to_base64(STANDARD);
println!("base64 output: {}", hello_str);
let res = hello_str.from_base64();
if res.is_ok() {
let opt_bytes = String::from_utf8(res.unwrap());
if opt_bytes.is_ok() {
println!("decoded from base64: {:?}", opt_bytes.unwrap());
}
}
}