Struct Track

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

The Track Type. This is a collection of Keys with a name.

Implementations§

Source§

impl Track

Source

pub fn new<S: Into<String>>(name: S) -> Track

Construct a new Track with a name.

Source

pub fn get_name(&self) -> &str

Get the name of the track.

Source

pub fn set_key(&mut self, key: Key)

Insert or update a key on a track.

Source

pub fn delete_key(&mut self, row: u32)

Delete a key from a track.

If a key does not exist this will do nothing.

Source

pub fn get_value(&self, row: f32) -> f32

Get a value based on a row.

The row can be between two integers. This will perform the required interpolation.

Examples found in repository?
examples/play.rs (line 28)
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}
More examples
Hide additional examples
examples/edit.rs (line 30)
8fn main() -> Result<(), Box<dyn Error>> {
9    let mut rocket = RocketClient::new()?;
10    rocket.get_track_mut("test")?;
11    rocket.get_track_mut("test2")?;
12    rocket.get_track_mut("a:test2")?;
13
14    let mut current_row = 0;
15    let mut paused = true;
16
17    loop {
18        if let Some(event) = rocket.poll_events()? {
19            match event {
20                Event::SetRow(row) => {
21                    println!("SetRow (row: {:?})", row);
22                    current_row = row;
23                }
24                Event::Pause(state) => {
25                    paused = state;
26
27                    let track1 = rocket.get_track("test").unwrap();
28                    println!(
29                        "Pause (value: {:?}) (row: {:?})",
30                        track1.get_value(current_row as f32),
31                        current_row
32                    );
33                }
34                Event::SaveTracks => {
35                    // Obtain a clone of current track state
36                    let tracks = rocket.save_tracks();
37
38                    // Open a file for writing, create if not present,
39                    // truncate (overwrite) in case it has previous contents.
40                    let mut file = OpenOptions::new()
41                        .write(true)
42                        .create(true)
43                        .truncate(true)
44                        .open(TRACKS_FILE)?;
45
46                    // Serialize tracks into the file using bincode
47                    let bincode_conf = bincode::config::standard();
48                    bincode::encode_into_std_write(tracks, &mut file, bincode_conf)?;
49                    // See examples/play.rs for deserializing and playback
50                    println!("Tracks saved to {}", TRACKS_FILE);
51                }
52            }
53            println!("{:?}", event);
54        }
55
56        if !paused {
57            current_row += 1;
58            rocket.set_row(current_row)?;
59        }
60
61        std::thread::sleep(Duration::from_millis(32));
62    }
63}

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for Track

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Clone for Track

Source§

fn clone(&self) -> Track

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Track

Source§

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

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

impl<__Context> Decode<__Context> for Track

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl<'de> Deserialize<'de> for Track

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Encode for Track

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl Serialize for Track

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Track

§

impl RefUnwindSafe for Track

§

impl Send for Track

§

impl Sync for Track

§

impl Unpin for Track

§

impl UnwindSafe for Track

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,