[][src]Enum metro::Event

pub enum Event<'a> {
    StartTrack(usize),
    StartTracks(&'a [usize]),
    StopTrack(usize),
    Station(usize, &'a str),
    SplitTrack(usizeusize),
    JoinTrack(usizeusize),
    NoEvent,
}

Events are produced automatically by using Metro, but can also be created and used manually.

An Event specifies an action and is used when rendering the metro lines graph.

Example

use metro::Event::*;

let events = [
    Station(0, "Station 1"),
    Station(0, "Station 2"),
    Station(0, "Station 3"),
    SplitTrack(0, 1),
    Station(1, "Station 4"),
    SplitTrack(1, 2),
    Station(1, "Station 5"),
    Station(2, "Station 6"),
    Station(0, "Station 7"),
    Station(1, "Station 8"),
    Station(2, "Station 9"),
    SplitTrack(2, 3),
    SplitTrack(3, 4),
    Station(5, "Station 10 (Detached)"),
    JoinTrack(4, 0),
    Station(3, "Station 11"),
    StopTrack(1),
    Station(0, "Station 12"),
    Station(2, "Station 13"),
    Station(3, "Station 14"),
    JoinTrack(3, 0),
    Station(2, "Station 15"),
    StopTrack(2),
    Station(0, "Station 16"),
];

let string = metro::to_string(&events).unwrap();

println!("{}", string);

This will output the following:

* Station 1
* Station 2
* Station 3
|\
| * Station 4
| |\
| * | Station 5
| | * Station 6
* | | Station 7
| * | Station 8
| | * Station 9
| | |\
| | | |\
| | | | | Station 10 (Detached)
| |_|_|/
|/| | |
| | | * Station 11
| " | |
|  / /
* | | Station 12
| * | Station 13
| | * Station 14
| |/
|/|
| * Station 15
| "
* Station 16

Variants

StartTrack(usize)

StartTrack(track_id)

  • If track_id already exists, then this event does nothing.

New track_ids are added rightmost.

Output Example

Given 3 tracks 0, 1, 2 then StartTrack(4) would render as:

| | |
| | | |
| | | |
StartTracks(&'a [usize])

StartTracks(track_ids)

  • If a track_id from track_ids already exists, then it is ignored.
  • If all track_ids already exists, then this event does nothing.

New track_ids are added rightmost.

Output Example

Given 3 tracks 0, 1, 2 then StartTracks(&[4, 5]) would render as:

| | |
| | | | |
| | | | |
StopTrack(usize)

StopTrack(track_id)

  • If track_id does not exist, then this event does nothing.

All rails to the right of track_id, are pulled to the left.

Output Example

Given 3 tracks 0, 1, 2 then StopTrack(1) would render as:

| | |
| " |
|  /
| |
Station(usize, &'a str)

Station(track_id, text)

  • If the track_id does not exist, then text is still rendered, just not tied to any track.

Output Example

Given 3 tracks 0, 1, 2 then Station(1, "Hello World") would render as:

| | |
| * | Hello World
| | |

If the track_id does not exist, then no rail is highlighted. Thus Station(10, "Hello World") would render as:

| | |
| | | Hello World
| | |
SplitTrack(usizeusize)

SplitTrack(from_track_id, new_track_id)

Creates a new track diverging from from_track_id to the right. All rails to the right of from_track_id, are pushed to the right to make space for the new track.

  • If from_track_id does not exist, then this event is the same as StartTrack(new_track_id).
  • If new_track_id already exists, then this event does nothing.

Output Example

Given 3 tracks 0, 1, 2 then SplitTrack(1, 4) would render as:

| | |
| |\ \
| | | |
JoinTrack(usizeusize)

JoinTrack(from_track_id, to_track_id)

Joins from_track_id and to_track_id resulting in the from_track_id being removed.

The rails are joined towards the leftmost rail.

  • If from_track_id does not exist, then this event does nothing.
  • If to_track_id does not exist, then it turns into StopTrack(from_track_id).
  • If from_track_id and to_track_id are the same, then it turns into StopTrack(from_track_id)

The track ID (from_track_id) can be reused for a new track after this event.

Output Example

Given 3 tracks 0, 1, 2 then JoinTrack(1, 0) would render as:

| | |
|/ /
| |

Given 6 tracks 0, 1, 2, 3, 4, 5 then JoinTrack(4, 0) would render as:

| | | | | |
| |_|_|/ /
|/| | | |
| | | | |
NoEvent

NoEvent produces one row of rails.

Output Example

Given 3 tracks 0, 1, 2 then NoEvent would render as:

| | |

Trait Implementations

impl<'a> Clone for Event<'a>[src]

impl<'a> Debug for Event<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Event<'a>

impl<'a> Send for Event<'a>

impl<'a> Sync for Event<'a>

impl<'a> Unpin for Event<'a>

impl<'a> UnwindSafe for Event<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.