Struct lb64::config::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§

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),
    }
}

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),
    }
}

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 /
}

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"),
    }
}

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),
    }
}

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"),
    }
}

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.