Struct ca_formats::macrocell::Macrocell[][src]

pub struct Macrocell<I: Input> { /* fields omitted */ }

A parser for Macrocell format.

This format is specifically designed for the HashLife algorithm. So as an iterator, it iterates over the nodes in the quadtree, instead of the living cells.

Examples

Reading from a string:

use ca_formats::macrocell::{Macrocell, NodeData};

const GLIDER: &str = r"[M2] (golly 3.4)
#R B3/S23
$$$$$$*$.*$
.......*$
**$
4 0 1 2 3";

let glider = Macrocell::new(GLIDER).unwrap();
assert_eq!(glider.rule().unwrap(), "B3/S23");

let last_node = glider.last().unwrap().unwrap();
assert_eq!(last_node.id, 4);
assert_eq!(
    last_node.data,
    NodeData::Node {
        level: 4,
        nw: 0,
        ne: 1,
        sw: 2,
        se: 3,
    }
);

Reading from a file:

use std::fs::File;
use ca_formats::macrocell::Macrocell;

let file = File::open("tests/sirrobin.mc").unwrap();
let sirrobin = Macrocell::new_from_file(file).unwrap();

assert_eq!(sirrobin.count(), 42); // The number of nodes.

Implementations

impl<I: Input> Macrocell<I>[src]

pub fn new(input: I) -> Result<Self, Error>[src]

Create a new parser instance from input, and try to read the header lines.

pub fn rule(&self) -> Option<&str>[src]

The rulestring.

pub fn gen(&self) -> Option<u64>[src]

The current generation.

impl<R: Read> Macrocell<BufReader<R>>[src]

pub fn new_from_file(file: R) -> Result<Self, Error>[src]

Creates a new parser instance from something that implements Read trait, e.g., a File.

Trait Implementations

impl<I: Input> Clone for Macrocell<I> where
    I::Lines: Clone,
    I::Line: Clone
[src]

impl<I: Debug + Input> Debug for Macrocell<I> where
    I::Lines: Debug,
    I::Line: Debug
[src]

impl<I: Input> Iterator for Macrocell<I>[src]

An iterator over quadtree nodes in an Macrocell file.

type Item = Result<Node, Error>

The type of the elements being iterated over.

Auto Trait Implementations

impl<I> RefUnwindSafe for Macrocell<I> where
    <I as Input>::Line: RefUnwindSafe,
    <I as Input>::Lines: RefUnwindSafe
[src]

impl<I> Send for Macrocell<I> where
    <I as Input>::Line: Send,
    <I as Input>::Lines: Send
[src]

impl<I> Sync for Macrocell<I> where
    <I as Input>::Line: Sync,
    <I as Input>::Lines: Sync
[src]

impl<I> Unpin for Macrocell<I> where
    <I as Input>::Line: Unpin,
    <I as Input>::Lines: Unpin
[src]

impl<I> UnwindSafe for Macrocell<I> where
    <I as Input>::Line: UnwindSafe,
    <I as Input>::Lines: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.