pub trait Format: Display {
    // Required methods
    fn rule(&self) -> Rule;
    fn live_cells(&self) -> Box<dyn Iterator<Item = Position<usize>> + '_>;
}
Expand description

Provides several methods for Conway’s Game of Life pattern file formats.

Required Methods§

source

fn rule(&self) -> Rule

Returns the rule.

Examples
use life_backend::{Format, Rule};
use life_backend::format::Rle;
let pattern = "\
    #N T-tetromino\n\
    x = 3, y = 2, rule = B3/S23\n\
    3o$bo!\n\
";
let handler: Box<dyn Format> = Box::new(pattern.parse::<Rle>()?);
assert_eq!(handler.rule(), Rule::conways_life());
source

fn live_cells(&self) -> Box<dyn Iterator<Item = Position<usize>> + '_>

Creates an owning iterator over the series of live cell positions in ascending order.

Examples
use life_backend::{Format, Position, Rule};
use life_backend::format::Rle;
let pattern = "\
    #N T-tetromino\n\
    x = 3, y = 2, rule = B3/S23\n\
    3o$bo!\n\
";
let handler: Box<dyn Format> = Box::new(pattern.parse::<Rle>()?);
assert!(handler.live_cells().eq([Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)]));

Implementors§