bigwise 0.4.0

Bitwise operations on fixed-size, arbitrary big buffer of bytes.
Documentation
//! Implementation of an elementary cellular automaton, more specifically the
//! rule 110 in Wolfram's classification.
//!
//! https://en.wikipedia.org/wiki/Rule_110

extern crate bigwise;

use bigwise::{Bigwise, Bw1k};
use std::io::Write;
use std::fs::File;
use std::env;

fn main() {
    run::<Bw1k>();
}

fn run<T:Bigwise>() {
    let w = T::size();
    let h = w;
    let mut filename = env::temp_dir();
    filename.push("rule_110.pbm");
    println!("writing to {}", filename.to_string_lossy());
    let mut f = File::create(filename).unwrap();
    write!(&mut f, "P4\n{} {}\n", w, h).unwrap();
    let mut state = T::from_bytes(&[1]);
    for _ in 0..h {
        f.write(&*state.to_bytes()).unwrap();
        state = next(state);
    }
}

fn next<T: Bigwise>(state: T) -> T {
    let l = state.rotate_left(1);
    let r = state.rotate_right(1);
    (state & !r) |  (state ^ l)
}