[−][src]Enum metro::Event
Event
s 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_id
s are added rightmost.
Output Example
Given 3 tracks 0, 1, 2
then StartTrack(4)
would render as:
| | |
| | | |
| | | |
StartTracks(track_ids)
- If a
track_id
fromtrack_ids
already exists, then it is ignored. - If all
track_ids
already exists, then this event does nothing.
New track_id
s 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(track_id, text)
- If the
track_id
does not exist, thentext
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(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 asStartTrack(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(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 intoStopTrack(from_track_id)
. - If
from_track_id
andto_track_id
are 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
produces one row of rails.
Output Example
Given 3 tracks 0, 1, 2
then NoEvent
would render as:
| | |
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,