Config

Struct Config 

Source
pub struct Config<'a> { /* private fields */ }
Expand description

Configuration for Base64 number that consists of

character_set: the characters the Base64 number can have. First character provided is given value 0 and so on until the 64th character which is value 63

pad: Optional padding character for the Base64 number

line_length: Optional maximum line length for the Base64 number

All characters must be graphically representable characters in UTF8

Implements Equals, Debug, and Clone

Implementations§

Source§

impl<'a> Config<'a>

Source

pub fn new( set: &'a [char], pad_char: Option<char>, len: Option<u8>, ) -> Result<Self, ConfigError>

Creates a config with provided values

§Parameters:

Character set of the base64 values

Optional: padding for base64

Optional: Fixed line length

§Returns:

Result<Self, base64::error::ConfigError> either the new config or an error of: CharacterSetLengthError, NotUniquePaddingError, DuplicateCharacterError, CharacterSetUnrepresentableCharacter, or PaddingUnrepresentableCharacter

§Example:
extern crate lb64;

use lb64::config::Config;

fn main() {
    let character_set = &[
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
    'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
    'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
    match Config::new(character_set, None, None) {
        Ok(conf) => println!("Successful"),
        Err(e) => println!("{}", e),
    }
}
Source

pub fn set_character_set(&mut self, set: &'a [char]) -> Result<(), ConfigError>

Sets the character set by the provided slice

§Returns:

A Result<(), base64::error::ConfigError> possible ConfigErrors are CharacterSetLengthError, DuplicateCharacterError, or CharacterSetUnrepresentableCharacter

§Example:
extern crate lb64;

use lb64::config::Config;

fn main() {
    let character_set_orig = &[
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
    'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
    'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
    let character_set_new = &[
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
    'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
    'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
];
    match Config::new(character_set_orig, None, None) {
        Ok(mut conf) => {
           match conf.set_character_set(character_set_new) {
                Ok(()) => println!("Successful!"), // Since there are no duplicate characters and character_set_new is of length 64 it's successful
                Err(e) => println!("{}", e),
           }
        },
        Err(e) => println!("{}", e),
    }
}
Source

pub fn get_character_set(&self) -> &[char]

Returns the slice of all the characters in the character set

§Example:
extern crate lb64;

use lb64::config::MIME;

fn main() {
    println!("{:?}", MIME.get_character_set()); // Prints a slice containing [A-Z], [a-z], [0-9], +, and /
}
Source

pub fn get_line_length(&self) -> Option<u8>

Return Line_length field

§Example:
extern crate lb64;

use lb64::config::MIME;

fn main() {
    match MIME.get_line_length() {
        Some(len) => println!("{}", len), // Prints 76
        None => println!("Line length for Mime isn't None"),
    }
}
Source

pub fn set_line_length(&mut self, len: Option<u8>)

Sets the maximum line length for a configuration

§Example:
extern crate lb64;

use lb64::config::Config;
use lb64::error::ConfigError;

fn main() {
    let character_set = &[
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
    'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
    'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
    match Config::new(character_set, None, None) {
        Ok(mut conf) => {
           conf.set_line_length(Some(5)); // Sets the line_length from None to 5
        },
        Err(e) => println!("{}", e),
    }
}
Source

pub fn get_padding(&self) -> Option<char>

Return Padding character

§Example:
extern crate lb64;

use lb64::config::MIME;

fn main() {
    match MIME.get_padding() {
        Some(pad) => println!("{}", pad), // Prints =
        None => println!("Padding for Mime isn't None"),
    }
}
Source

pub fn set_padding(&mut self, pad_char: Option<char>) -> Result<(), ConfigError>

Sets the padding character

§Returns:

Returns a result of <(), base64::error::ConfigError> the ConfigError is either NotUniquePaddingError or PaddingUnrepresentableCharacter

§Example:
extern crate lb64;

use lb64::config::Config;

fn main() {
    let character_set = &[
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
    'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
    'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
    match Config::new(character_set, None, None) {
        Ok(mut conf) => {
            match conf.set_padding(Some('/')) {
                Ok(()) => println!("Set padding character successful!"),
                Err(e) => println!("{}", e), // This occurs because / is already taken
            }
        },
        Err(e) => println!("{}", e),
    }
}

Trait Implementations§

Source§

impl<'a> Clone for Config<'a>

Source§

fn clone(&self) -> Config<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Config<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for Config<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Config<'a>

Source§

fn eq(&self, other: &Config<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for Config<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Config<'a>

§

impl<'a> RefUnwindSafe for Config<'a>

§

impl<'a> Send for Config<'a>

§

impl<'a> Sync for Config<'a>

§

impl<'a> Unpin for Config<'a>

§

impl<'a> UnwindSafe for Config<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.