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
impl RocketPlayer
Sourcepub fn new(tracks: Tracks) -> Self
pub fn new(tracks: Tracks) -> Self
Constructs a RocketPlayer
from Track
s.
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}
Sourcepub fn get_track(&self, name: &str) -> Option<&Track>
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§
impl Freeze for RocketPlayer
impl RefUnwindSafe for RocketPlayer
impl Send for RocketPlayer
impl Sync for RocketPlayer
impl Unpin for RocketPlayer
impl UnwindSafe for RocketPlayer
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