Skip to main content

AutomatonImpl

Trait AutomatonImpl 

Source
pub trait AutomatonImpl {
    // Required methods
    fn new(states: u8, size: usize, rule: Rule) -> Self;
    fn skipped_iter(
        &mut self,
        steps: u32,
        skip: u32,
        scale: u16,
    ) -> Box<dyn Iterator<Item = Vec<u8>> + '_>;
    fn size(&self) -> usize;
    fn states(&self) -> u8;
    fn init_from_pattern(&mut self, pattern_fname: &str);
    fn update(&mut self);
    fn random_init(&mut self);
    fn grid(&self) -> Vec<u8> ;

    // Provided method
    fn iter(&mut self, steps: u32) -> Box<dyn Iterator<Item = Vec<u8>> + '_> { ... }
}
Expand description

An automaton must implement this trait.

Required Methods§

Source

fn new(states: u8, size: usize, rule: Rule) -> Self

Make a new cellular automaton with a given grid size, number of states per cells and rule.

use rust_ca::rule::Rule;
use rust_ca::automaton::Automaton;
use rust_ca::automaton::AutomatonImpl;
let automaton = Automaton::new(3, 128, Rule::random(1, 2));
Source

fn skipped_iter( &mut self, steps: u32, skip: u32, scale: u16, ) -> Box<dyn Iterator<Item = Vec<u8>> + '_>

Returns an boxed iterator of CA steps, skipping every skip step and scaling the grid by a factor scale.

Source

fn size(&self) -> usize

Returns the size of the automaton.

Source

fn states(&self) -> u8

Returns the number of states of the automaton.

Source

fn init_from_pattern(&mut self, pattern_fname: &str)

Initialize all the cells of the grid from a pattern file.

Source

fn update(&mut self)

Perform a single step update of the CA grid according to the rule.

Source

fn random_init(&mut self)

Randomly set all the cells of the cellular automaton grid

Source

fn grid(&self) -> Vec<u8>

Get the current grid.

Provided Methods§

Source

fn iter(&mut self, steps: u32) -> Box<dyn Iterator<Item = Vec<u8>> + '_>

Returns a boxed iterator of CA steps.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§