pub enum Event<'a> {
StartTrack(usize),
StartTracks(&'a [usize]),
StopTrack(usize),
Station(usize, &'a str),
SplitTrack(usize, usize),
JoinTrack(usize, usize),
NoEvent,
}Expand description
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 16Variants§
StartTrack(usize)
StartTrack(track_id)
- If
track_idalready 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_idfromtrack_idsalready exists, then it is ignored. - If all
track_idsalready 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_iddoes 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_iddoes not exist, thentextis 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(usize, usize)
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_iddoes not exist, then this event is the same asStartTrack(new_track_id). - If
new_track_idalready exists, then this event does nothing.
§Output Example
Given 3 tracks 0, 1, 2 then SplitTrack(1, 4) would render as:
| | |
| |\ \
| | | |JoinTrack(usize, usize)
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_iddoes not exist, then this event does nothing. - If
to_track_iddoes not exist, then it turns intoStopTrack(from_track_id). - If
from_track_idandto_track_idare the same, then it turns intoStopTrack(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:
| | |