pub struct HuffmanData {
pub encoded_data: Vec<u8>,
pub encoding_map: HashMap<u8, String>,
pub stats: EncodingStats,
}Expand description
Huffman encoded data
Fields§
§encoded_data: Vec<u8>The encoded data as a Vec<u8>
encoding_map: HashMap<u8, String>Encoding map stored as a EncodingMap required for decoding the data
stats: EncodingStatsEncoding stats for the data
Implementations§
Source§impl HuffmanData
impl HuffmanData
Sourcepub fn new(data: &[u8]) -> Result<HuffmanData, HuffmanError<'static>>
pub fn new(data: &[u8]) -> Result<HuffmanData, HuffmanError<'static>>
Huffman encodes a Vec<u8> returning a HuffmanData struct
§Arguments
data- A reference toVec<u8>containing the data you want to encode
§Examples
extern crate huff_tree_tap;
use huff_tree_tap::*;
use std::collections::HashMap;
let data: Vec<u8> = Vec::<u8>::from("this is a test string!");
let huffman_data: HuffmanData = HuffmanData::new(&data).unwrap();
let decoded_data: Vec<u8> = huffman_data.decode().unwrap();
assert_eq!(decoded_data,data);Sourcepub fn decode(&self) -> Result<Vec<u8>, HuffmanError<'static>>
pub fn decode(&self) -> Result<Vec<u8>, HuffmanError<'static>>
Huffman decodes a HuffmanData struct and returns a decoded Vec<u8>
§Arguments
huffman_encoded_data- A reference toHuffmanDatacontaining the encoded data and encoding map
§Examples
extern crate huff_tree_tap;
use huff_tree_tap::*;
use std::collections::HashMap;
let data: Vec<u8> = Vec::from("this is a test string!");
let huffman_data: HuffmanData = HuffmanData::new(&data).unwrap();
let decoded_data: Vec<u8> = huffman_data.decode().unwrap();
assert_eq!(decoded_data,data);Trait Implementations§
Auto Trait Implementations§
impl Freeze for HuffmanData
impl RefUnwindSafe for HuffmanData
impl Send for HuffmanData
impl Sync for HuffmanData
impl Unpin for HuffmanData
impl UnwindSafe for HuffmanData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more