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]

Create a new, empty ruleset.

Set an atom to produce a vector

impl MapRules<char>
[src]

Set an atom to produce the Vec corresponding to a string

Trait Implementations

impl<T: ?Sized> LRules<T> for MapRules<T> where
    T: Clone + Hash + Eq
[src]

perform a mapping of one atom to a string. It returns Some(Vec<T>) if the atom is a variable with an existing production rule, or None if the atom should be considered terminal. Read more