[![base64-badge]][base64] [![cat-encoding-badge]][cat-encoding]
将字节切片编码为base64
字符串,通过encode
完成,还能用decode
解码。
# #[macro_use]
# extern crate error_chain;
extern crate base64;
use std::str;
use base64::{encode, decode};
#
# error_chain! {
# foreign_links {
# Base64(base64::DecodeError);
# Utf8Error(str::Utf8Error);
# }
# }
fn run() -> Result<()> {
let hello = b"hello rustaceans";
let encoded = encode(hello);
let decoded = decode(&encoded)?;
println!("origin: {}", str::from_utf8(hello)?);
println!("base64 encoded: {}", encoded);
println!("back to origin: {}", str::from_utf8(&decoded)?);
Ok(())
}
#
# quick_main!(run);