Struct lsystem::MapRules
[−]
[src]
pub struct MapRules<T: Hash + Eq> { /* fields omitted */ }
A simple production ruleset that maps an atom to an atom string using a lookup table.
Examples
MapRules can be used to create L-system rules for any hashable type.
use lsystem::{MapRules, LRules}; let mut rules = MapRules::new(); rules.set(0, vec![0, 1]); rules.set(1, vec![1, 1, 2]); assert_eq!(Some(vec![0, 1]), rules.map(&0)); assert_eq!(Some(vec![1, 1, 2]), rules.map(&1)); assert_eq!(None, rules.map(&3));
If you are working with characters, MapRules has the set_str
convenience
function to make it easier to work with strings.
use lsystem::{MapRules, LRules}; let mut rules = MapRules::new(); rules.set_str('A', "AB"); rules.set_str('B', "A"); assert_eq!(Some("AB".chars().collect()), rules.map(&'A'));
Methods
impl<T> MapRules<T> where
T: Hash + Eq,
[src]
T: Hash + Eq,
fn new() -> MapRules<T>
Create a new, empty ruleset.
fn set(&mut self, k: T, v: Vec<T>) -> Option<Vec<T>>
Set an atom to produce a vector
impl MapRules<char>
[src]
fn set_str(&mut self, k: char, v: &str) -> Option<Vec<char>>
Set an atom to produce the Vec
Trait Implementations
impl<T: ?Sized> LRules<T> for MapRules<T> where
T: Clone + Hash + Eq,
[src]
T: Clone + Hash + Eq,