[][src]Trait dcc_lsystem::turtle::Turtle

pub trait Turtle {
    fn inner(&self) -> &BaseTurtle;
fn inner_mut(&mut self) -> &mut BaseTurtle;
fn forward(&mut self, distance: i32); }

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, Turtle};

struct DumbTurtle {
    inner: BaseTurtle,
}

impl Turtle for DumbTurtle {
    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);
    }
}

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: i32)

Moves the turtle forward by distance.

Loading content...

Implementors

impl Turtle for StackTurtle[src]

impl Turtle for TaxiTurtle[src]

Loading content...