pub struct Metro<'a> { /* private fields */ }Expand description
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 16Implementations§
Source§impl<'a> Metro<'a>
impl<'a> Metro<'a>
Sourcepub fn new_track_with_id(&mut self, track_id: usize) -> Track<'a>
pub fn new_track_with_id(&mut self, track_id: usize) -> Track<'a>
Sourcepub fn get_track(&mut self, track_id: usize) -> Option<Track<'a>>
pub fn get_track(&mut self, track_id: usize) -> Option<Track<'a>>
If the track_id exists then Some is returned, otherwise None.
Sourcepub fn add_station(&mut self, text: &'a str)
pub fn add_station(&mut self, text: &'a str)
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.
Sourcepub fn to_events(&self) -> Vec<Event<'a>>
pub fn to_events(&self) -> Vec<Event<'a>>
Auto Trait Implementations§
impl<'a> Freeze for Metro<'a>
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> UnsafeUnpin for Metro<'a>
impl<'a> !UnwindSafe for Metro<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more