[][src]Trait dcc_lsystem::turtle::MovingTurtle

pub trait MovingTurtle {
    type Item;
    fn inner(&self) -> &BaseTurtle;
fn inner_mut(&mut self) -> &mut BaseTurtle;
fn forward(&mut self, distance: Self::Item); }

A simple trait for an integer-valued Turtle.

Any implementation of this trait should contain a BaseTurtle struct which is referred to by the inner and inner_mut methods. This BaseTurtle deals with storing the turtle's current position, and drawing lines as appropriate.

The real meat and potatoes of this trait is the forward method, which is how someone would actually move your turtle. Your implementation should be responsible for keeping track of the turtle's heading, and forward should move your turtle in that direction (using self.inner_mut().delta_move(dx, dy)).

Future

In the future the Turtle trait may be modified by the addition of a set_heading() method generic over some Heading trait.

Example

The following DumbTurtle only moves to the right.

use dcc_lsystem::turtle::{BaseTurtle, MovingTurtle};

struct DumbTurtle {
    inner: BaseTurtle,
}

impl MovingTurtle for DumbTurtle {
    type Item = i32;

    fn inner(&self) -> &BaseTurtle {
        &self.inner
    }

    fn inner_mut(&mut self) -> &mut BaseTurtle {
        &mut self.inner
    }

    fn forward(&mut self, distance: i32) {
        self.inner_mut().delta_move(distance, 0);
    }
}

Associated Types

type Item

Loading content...

Required methods

fn inner(&self) -> &BaseTurtle

Returns a reference to the wrapped BaseTurtle.

fn inner_mut(&mut self) -> &mut BaseTurtle

Returns a mutable reference to the wrapped BaseTurtle.

fn forward(&mut self, distance: Self::Item)

Moves the turtle forward by distance.

Loading content...

Trait Implementations

impl<T> TurtleContainer for dyn MovingTurtle<Item = T>[src]

Every turtle contains a turtle

type Item = T

Implementors

impl MovingTurtle for LatticeTurtle[src]

type Item = (i32, i32)

impl MovingTurtle for SimpleTurtle[src]

type Item = i32

Loading content...