Skip to main content

Event

Enum Event 

Source
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 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(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_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(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_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§

Source§

impl<'a> Clone for Event<'a>

Source§

fn clone(&self) -> Event<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Event<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Event<'a>

§

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> UnsafeUnpin for Event<'a>

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.