Trait bitstream_io::write::HuffmanWrite[][src]

pub trait HuffmanWrite<E: Endianness> {
    fn write_huffman<T>(
        &mut self,
        tree: &WriteHuffmanTree<E, T>,
        symbol: T
    ) -> Result<()>
    where
        T: Ord + Copy
; }
Expand description

A trait for anything that can write Huffman codes of a given endianness to an output stream

Required methods

Writes Huffman code for the given symbol to the stream.

Errors

Passes along any I/O error from the underlying stream.

Implementors

Example

use std::io::Write;
use bitstream_io::{BigEndian, BitWriter, HuffmanWrite};
use bitstream_io::huffman::compile_write_tree;
let tree = compile_write_tree(
    vec![('a', vec![0]),
         ('b', vec![1, 0]),
         ('c', vec![1, 1, 0]),
         ('d', vec![1, 1, 1])]).unwrap();
let mut writer = BitWriter::endian(Vec::new(), BigEndian);
writer.write_huffman(&tree, 'b').unwrap();
writer.write_huffman(&tree, 'c').unwrap();
writer.write_huffman(&tree, 'd').unwrap();
assert_eq!(writer.into_writer(), [0b10110111]);