Skip to main content

Track

Struct Track 

Source
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.

See Metro for a complete example.

Implementations§

Source§

impl<'a> Track<'a>

Source

pub fn id(&self) -> usize

Returns the track id.

Source

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.

See is_dangling for more information.

Source

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.

Source

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.

Source

pub fn split_with_id(&self, new_track_id: usize) -> Track<'a>

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.

Source

pub fn join(self, to_track: &Track<'_>)

Merges self with to_track, removing self from the Metro.

Source

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());

Trait Implementations§

Source§

impl Debug for Track<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Drop for Track<'a>

Source§

fn drop(&mut self)

Drop implicitly calls Track::stop.

Auto Trait Implementations§

§

impl<'a> Freeze for Track<'a>

§

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

§

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