Struct RocketPlayer

Source
pub struct RocketPlayer { /* private fields */ }
Expand description

A player for tracks from RocketClient::save_tracks.

§Usage

See module-level documentation.

§Examples

// Run the demo and edit your sync tracks (see top level documentation),
// then call save_tracks and serialize tracks to a file (see save_tracks documentation)

// And deserialize from a file in your release build
let mut file = File::open("tracks.bin").expect("Failed to open tracks.bin");
let tracks = bincode::decode_from_std_read(&mut file, bincode::config::standard())
    .expect("Failed to decode tracks.bin");
let player = RocketPlayer::new(tracks);
println!("Value at row 123: {}", player.get_track("test").unwrap().get_value(123.));

Implementations§

Source§

impl RocketPlayer

Source

pub fn new(tracks: Tracks) -> Self

Constructs a RocketPlayer from Tracks.

Examples found in repository?
examples/play.rs (line 16)
8fn main() -> Result<(), Box<dyn Error>> {
9    let rocket = {
10        // Open previously saved file (see examples/edit.rs)
11        let mut file = File::open(TRACKS_FILE)?;
12        // Deserialize from the file into Vec<Track> using bincode
13        let bincode_conf = bincode::config::standard();
14        let tracks = bincode::decode_from_std_read(&mut file, bincode_conf)?;
15        // Construct a new read-only, offline RocketPlayer
16        RocketPlayer::new(tracks)
17    };
18    println!("Tracks loaded from {}", TRACKS_FILE);
19
20    let mut current_row = 0;
21
22    loop {
23        println!(
24            "value: {:?} (row: {:?})",
25            rocket
26                .get_track("test")
27                .unwrap()
28                .get_value(current_row as f32),
29            current_row
30        );
31
32        current_row += 1;
33        std::thread::sleep(Duration::from_millis(32));
34    }
35}
Source

pub fn get_track(&self, name: &str) -> Option<&Track>

Get track by name.

Examples found in repository?
examples/play.rs (line 26)
8fn main() -> Result<(), Box<dyn Error>> {
9    let rocket = {
10        // Open previously saved file (see examples/edit.rs)
11        let mut file = File::open(TRACKS_FILE)?;
12        // Deserialize from the file into Vec<Track> using bincode
13        let bincode_conf = bincode::config::standard();
14        let tracks = bincode::decode_from_std_read(&mut file, bincode_conf)?;
15        // Construct a new read-only, offline RocketPlayer
16        RocketPlayer::new(tracks)
17    };
18    println!("Tracks loaded from {}", TRACKS_FILE);
19
20    let mut current_row = 0;
21
22    loop {
23        println!(
24            "value: {:?} (row: {:?})",
25            rocket
26                .get_track("test")
27                .unwrap()
28                .get_value(current_row as f32),
29            current_row
30        );
31
32        current_row += 1;
33        std::thread::sleep(Duration::from_millis(32));
34    }
35}

Auto Trait Implementations§

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.