Trait rustc_serialize::base64::FromBase64 [] [src]

pub trait FromBase64 {
    fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>;
}

A trait for converting from base64 encoded values.

Required Methods

Converts the value of self, interpreted as base64 encoded data, into an owned vector of bytes, returning the vector.

Implementations on Foreign Types

impl FromBase64 for str
[src]

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());
      }
    }
}

impl FromBase64 for [u8]
[src]

impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T
[src]

Implementors