Skip to main content

Base64

Trait Base64 

Source
pub trait Base64 {
    // Required methods
    fn encode(&self) -> Result<String, Base64Error>;
    fn decode(&self) -> Result<String, Base64Error>;
}

Required Methods§

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Base64 for String

Source§

fn encode(&self) -> Result<String, Base64Error>

Encodes a String with the base64 scheme

Example:

use lib_base64::Base64;
let s = String::from("Test");
assert_eq!(Ok(String::from("VGVzdA==")), s.encode())
Source§

fn decode(&self) -> Result<String, Base64Error>

Decodes a String encoded with the base64 scheme

Example:

use lib_base64::Base64;
let s = String::from("VGVzdA==");
assert_eq!(Ok(String::from("Test")), s.decode())
Source§

impl Base64 for Vec<u8>

Source§

fn encode(&self) -> Result<String, Base64Error>

Encodes a Vec<u8> with the base64 scheme

Example:

use lib_base64::Base64;
let v = vec![0x4d, 0x61, 0x6e];
assert_eq!(Ok(String::from("TWFu")), v.encode())
Source§

fn decode(&self) -> Result<String, Base64Error>

Decodes a Vec<u8> encoded with the base64 scheme

Example:

use lib_base64::Base64;
let s = vec![0x54, 0x57, 0x45, 0x3d];
assert_eq!(Ok(String::from("Ma")), s.decode())

Implementors§