[−][src]Struct metro::Track
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
.
Methods
impl<'a> Track<'a>
[src]
pub fn id(&self) -> usize
[src]
Returns the track id.
pub fn stop(self)
[src]
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.
pub fn add_station(&mut self, text: &'a str)
[src]
Creates a station that is tied to this Track
.
See Metro::add_station
to create a station that is
tied to a Track
.
pub fn split(&self) -> Track<'a>
[src]
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.
pub fn split_with_id(&self, new_track_id: usize) -> Track<'a>
[src]
Create a new Track
that branches of from this track.
To create a new Track
without a specific track id
, then use split
.
Panics
Panics if more than usize
tracks have been created.
pub fn join(self, to_track: &Track)
[src]
Merges self
with to_track
, removing self
from
the Metro
.
pub fn is_dangling(&self) -> bool
[src]
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 Track
s 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());
Trait Implementations
impl<'_> Debug for Track<'_>
[src]
impl<'a> Drop for Track<'a>
[src]
fn drop(&mut self)
[src]
Drop implicitly calls Track::stop
.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Track<'a>
impl<'a> !Send for Track<'a>
impl<'a> !Sync for Track<'a>
impl<'a> Unpin for Track<'a>
impl<'a> !UnwindSafe for Track<'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, 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>,