[][src]Struct metro::Metro

pub struct Metro<'a> { /* fields omitted */ }

The Metro struct is essentially a more friendly way and builder for creating an Event stream (&[Event]).

The edge cases of using Events manually and creating a &[Event], is not possible using Metro and Track.

If you have a need for Arc then feel free to submit an issue on the issue tracker with your use case.

Example

use metro::Metro;

let mut metro = Metro::new();

let mut track1 = metro.new_track();
track1.add_station("Station 1");
track1.add_station("Station 2");
track1.add_station("Station 3");

let mut track2 = track1.split();
track2.add_station("Station 4");

let mut track3 = track2.split();
track2.add_station("Station 5");
track3.add_station("Station 6");

track1.add_station("Station 7");
track2.add_station("Station 8");
track3.add_station("Station 9");

let mut track4 = track3.split();
let track5 = track4.split();

metro.add_station("Station 10 (Detached)");

track5.join(&track1);

track4.add_station("Station 11");

track2.stop();

track1.add_station("Station 12");
track3.add_station("Station 13");
track4.add_station("Station 14");

track4.join(&track1);

track3.add_station("Station 15");

track3.stop();

track1.add_station("Station 16");

let string = metro.to_string().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

Methods

impl<'a> Metro<'a>[src]

pub fn new() -> Self[src]

Create a new Metro.

pub fn new_track(&mut self) -> Track<'a>[src]

Create a new Track.

To create a new Track with a specific track id, then use new_track_with_id.

Panics

Panics if more than usize tracks have been created.

pub fn new_track_with_id(&mut self, track_id: usize) -> Track<'a>[src]

Create a new Track with a specific track id.

If the track id is already in use, then this call has the same effect as calling get_track(id).unwrap().

To create a new Track without a specific track id, then use new_track.

Panics

Panics if more than usize tracks have been created.

pub fn get_track(&mut self, track_id: usize) -> Option<Track<'a>>[src]

If the track_id exists then Some is returned, otherwise None.

pub fn add_station(&mut self, text: &'a str)[src]

Creates a station that is not tied to any Track.

See Track::add_station to create a station that is tied to a Track.

Note that all stations require a track_id, so it uses std::usize::MAX as track_id.

pub fn to_writer<W: Write>(&self, writer: W) -> Result<(), Error>[src]

pub fn to_vec(&self) -> Result<Vec<u8>, Error>[src]

pub fn to_string(&self) -> Result<String, Error>[src]

pub fn to_events(&self) -> Vec<Event<'a>>[src]

Returns Vec<Event> of the events currently in this Metro.

See also into_events.

See also Metro::to_string.

pub fn into_events(self) -> Vec<Event<'a>>[src]

Consumes Metro and returns its Vec<Event> of the events.

See also to_events.

See also Metro::to_string.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Metro<'a>

impl<'a> !Send for Metro<'a>

impl<'a> !Sync for Metro<'a>

impl<'a> Unpin for Metro<'a>

impl<'a> !UnwindSafe for Metro<'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, 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.