ignite 0.1.6

ignite serves the role as a "batteries included" addon to stdlib providing useful stuff and higher level functions along with abstractions.
Documentation
use super::compressor::Compressor;
use super::COMPRESSIONDEFAULT;
use snap;
use std::fmt;
use std::str;
use std::string::String;
use std::vec::Vec;
use str_util::to_bytes;

/// The PointString, a string variant comprised of a Vec<u8> which provides easy access and manipulation of individual
/// bytes with support for in memory compression of strings.
#[derive(Debug, Clone)]
pub struct PString {
    pub compression: bool,
    codepoints: Vec<u8>,
}

// Implement the display trait.
impl fmt::Display for PString {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.clone().to_string_backend())
    }
}

impl PString {
    /// Create a new, empty PString.
    #[inline]
    pub fn new() -> PString {
        PString {
            compression: COMPRESSIONDEFAULT,
            codepoints: Vec::new(),
        }
    }

    /// Get a specific char.
    #[inline]
    pub fn char_at(&self, index: usize) -> char {
        let bytes = self.decompress_to_bytes();

        bytes[index] as char
    }

    /// Create a new PString with a certain preallocated capacity to save reallocations.
    #[inline]
    pub fn with_capacity(capacity: usize) -> PString {
        PString {
            compression: COMPRESSIONDEFAULT,
            codepoints: Vec::with_capacity(capacity),
        }
    }

    /// Create a new PString with a Vec of bytes.
    #[inline]
    pub fn from_bytes(codepoints: Vec<u8>) -> PString {
        PString {
            compression: COMPRESSIONDEFAULT,
            codepoints: Compressor::compress_bytes(codepoints, COMPRESSIONDEFAULT),
        }
    }

    /// Set the bytes of an existing PString.
    #[inline]
    pub fn set_bytes(&mut self, codepoints: Vec<u8>) {
        self.codepoints = Compressor::compress_bytes(codepoints, self.compression);
    }

    /// Set a existing PString to a str.
    #[inline]
    pub fn set_str(&mut self, string: &'static str) {
        self.codepoints = Compressor::compress_bytes(to_bytes::str_to_bytes(string), self.compression);
    }

    /// Set a existing PString to a str.
    #[inline]
    pub fn set_string(&mut self, string: String) {
        self.codepoints = Compressor::compress_bytes(to_bytes::string_to_bytes(string), self.compression);
    }

    /// Create a PString from a str pointer.
    #[inline]
    pub fn from_str(string: &'static str) -> PString {
        let returnvalue: PString = PString::from_bytes(to_bytes::str_to_bytes(string));

        returnvalue
    }

    /// Create a PString from a String.
    #[inline]
    pub fn from_string(string: String) -> PString {
        let returnvalue: PString = PString::from_bytes(to_bytes::string_to_bytes(string));

        returnvalue
    }

    /// Backend private function to convert to a string.
    #[inline]
    fn to_string_backend(&mut self) -> String {
        let bytes = Compressor::decompress_bytes(self.codepoints.clone(), self.compression);

        String::from_utf8(bytes).unwrap()
    }

    /// Get the individual bytes that make up a PString.
    #[inline]
    pub fn as_bytes(&mut self) -> Vec<u8> {
        self.decompress_to_bytes()
    }

    /// Get the individual raw bytes that make up a PString.
    #[inline]
    pub fn as_bytes_raw(&self) -> Vec<u8> {
        self.codepoints.clone()
    }

    /// Get a Vec of all chars in the pstring.
    pub fn chars(&self) -> Vec<char> {
        let mut chararray: Vec<char> = Vec::new();
        for byte in self.decompress_to_bytes() {
            chararray.push(byte as char);
        }

        chararray
    }

    /// Enable compression.
    pub fn compress(&mut self) {
        if self.compression == false {
            let mut encoder = snap::Encoder::new();
            self.codepoints = encoder.compress_vec(&self.codepoints[..]).unwrap();
            self.compression = true;
        }
    }

    /// Disable compression.
    pub fn decompress(&mut self) {
        if self.compression == true {
            let mut decoder = snap::Decoder::new();
            self.codepoints = decoder.decompress_vec(&self.codepoints[..]).unwrap();
            self.compression = false;
        }
    }

    /// Compress a codepoints byte struct.
    #[allow(dead_code)]
    #[inline(always)]
    fn compress_to_bytes(&self) -> Vec<u8> {
        if self.compression == true {
            let mut encoder = snap::Encoder::new();
            return encoder.compress_vec(&self.codepoints[..]).unwrap();
        }

        self.codepoints.clone()
    }

    /// Decompress a codepoints byte struct
    #[allow(dead_code)]
    #[inline(always)]
    fn decompress_to_bytes(&self) -> Vec<u8> {
        if self.compression == true {
            let mut decoder = snap::Decoder::new();
            return decoder.decompress_vec(&self.codepoints[..]).unwrap();
        }

        self.codepoints.clone()
    }

    /// Autocompress data if enabled.
    #[allow(dead_code)]
    #[inline(always)]
    fn autocompress(&mut self) {
        if self.compression {
            let mut encoder = snap::Encoder::new();
            self.codepoints = encoder.compress_vec(&self.codepoints[..]).unwrap();
        }
    }

    /// Autodecompress data if enabled.
    #[allow(dead_code)]
    #[inline(always)]
    fn autodecompress(&mut self) {
        if self.compression {
            let mut decoder = snap::Decoder::new();
            self.codepoints = decoder.decompress_vec(&self.codepoints[..]).unwrap();
        }
    }
}