pub struct Track<'a> { /* private fields */ }Expand description
The Track struct represents a track in the Metro.
The Track struct is created with the new_track or
new_track_with_id on Metro.
Implementations§
Source§impl<'a> Track<'a>
impl<'a> Track<'a>
Sourcepub fn stop(self)
pub fn stop(self)
Stop this Track, and removes it from Metro.
The track id can be reused after with new_track_with_id.
§Dangling Tracks
If other tracks exist, which has the same track id, e.g. by
calling get_track multiple times with the same track id, then
the other tracks become “dangling”. However, if a new track is created
with new_track_with_id, then the other references are
not dangling anymore.
Sourcepub fn add_station(&mut self, text: &'a str)
pub fn add_station(&mut self, text: &'a str)
Creates a station that is tied to this Track.
See Metro::add_station to create a station that is
tied to a Track.
Sourcepub fn split(&self) -> Track<'a>
pub fn split(&self) -> Track<'a>
Create a new Track that branches of from this 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.
Sourcepub fn split_with_id(&self, new_track_id: usize) -> Track<'a>
pub fn split_with_id(&self, new_track_id: usize) -> Track<'a>
Sourcepub fn join(self, to_track: &Track<'_>)
pub fn join(self, to_track: &Track<'_>)
Merges self with to_track, removing self from
the Metro.
Sourcepub fn is_dangling(&self) -> bool
pub fn is_dangling(&self) -> bool
Returns true if the Track has been removed from
its Metro.
Note if a new track is created in the same Metro, with
the same track id, then self is no longer dangling
and the two Tracks represent the same Track.
§Example
let mut metro = Metro::new();
// Create a new track with track id `0`
let mut track1 = metro.new_track_with_id(0);
// Get a second reference to the track with track id `0`
let mut track2 = metro.get_track(0).unwrap();
// They represent the same track, so `is_dangling` returns `false` for both
assert!(!track1.is_dangling());
assert!(!track2.is_dangling());
// Stop the track
track1.stop();
// or
// drop(track1);
// Now `track2` is dangling as `track1` was stopped and they share track id
assert!(track2.is_dangling());
// Create a new track that uses the same track id `0`
let mut track3 = metro.new_track_with_id(0);
// Now `track2` and `track3` represent the same track,
// so `is_dangling` again returns `false` for both
assert!(!track2.is_dangling());
assert!(!track3.is_dangling());