Trait ca_rules::ParseNtNeumann
source · pub trait ParseNtNeumann {
// Required method
fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self;
// Provided method
fn parse_rule(input: &str) -> Result<Self, ParseRuleError>
where Self: Sized { ... }
}
Expand description
A trait for parsing non-totalistic rules with von Neumann neighborhood. Both isotropic and non-isotropic rules are supported.
The b
/ s
data of this type of rules consists of possible combinations of
states of the 4 neighbors, represented by an 8-bit binary number,
that cause a cell to be born / survive.
For example, the following neighborhood is represented by the number 10 = 0b1010
:
1
0 _ 1
0
Examples
use ca_rules::ParseNtNeumann;
#[derive(Debug, Eq, PartialEq)]
struct Rule {
b: Vec<u8>,
s: Vec<u8>,
}
impl ParseNtNeumann for Rule {
fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self {
Rule { b, s }
}
}
let life = Rule::parse_rule("MAPHmlphg").unwrap();
assert!(life.s.contains(&0x00));
Required Methods§
Provided Methods§
sourcefn parse_rule(input: &str) -> Result<Self, ParseRuleError>where
Self: Sized,
fn parse_rule(input: &str) -> Result<Self, ParseRuleError>where Self: Sized,
The parser.
Object Safety§
This trait is not object safe.