macro_rules! define_huffman_tree {
($name:ident : $type:ty = $nodes:tt) => { ... };
}
Expand description
Defines a new Huffman tree for reading and writing
Its syntax is: define_huffman_tree!(name : type = nodes)
where name
is some identifier to identify the tree in the
macro’s current scope, type
is the tree’s output
type (which should implement Copy
and Eq
), and nodes
is either a
final leaf value or a [bit_0, bit_1]
pair where bit_0
is
the tree visited on a 0
bit, and bit_1
is the tree visited
on a 1
bit.
§Example
use bitstream_io::{define_huffman_tree, huffman::FromBits};
define_huffman_tree!(TreeName : &'static str = ["bit 0", ["bit 1->0", "bit 1->1"]]);
let mut bits = [true, false].iter().copied();
assert_eq!(TreeName::from_bits(|| bits.next().ok_or(())).unwrap(), "bit 1->0");