Struct RocketClient

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

The RocketClient type. This contains the connected socket and other fields.

Implementations§

Source§

impl RocketClient

Source

pub fn new() -> Result<Self, Error>

Construct a new RocketClient.

This constructs a new Rocket client and connects to localhost on port 1338.

§Errors

Error::Connect if connection cannot be established, or Error::Handshake if the handshake fails.

§Examples
let mut rocket = RocketClient::new()?;
Source

pub fn connect(addr: impl ToSocketAddrs) -> Result<Self, Error>

Construct a new RocketClient.

This constructs a new Rocket client and connects to a specified host and port.

§Errors

Error::Connect if connection cannot be established, or Error::Handshake if the handshake fails.

§Examples
let mut rocket = RocketClient::connect(("localhost", 1338))?;
Source

pub fn get_track_mut(&mut self, name: &str) -> Result<&mut Track, Error>

Get track by name.

If the track does not yet exist it will be created.

§Errors

This method can return an Error::IOError if Rocket tracker disconnects.

§Panics

Will panic if name’s length exceeds u32::MAX.

§Examples
let track = rocket.get_track_mut("namespace:track")?;
track.get_value(3.5);
Source

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

Get track by name.

You should use get_track_mut to create a track.

Source

pub fn save_tracks(&self) -> &Tracks

Get a snapshot of the tracks in the session.

The returned Tracks can be dumped to a file in any supported format. The counterpart to this function is RocketPlayer::new, which loads tracks for playback.

§Example
let mut rocket = RocketClient::new()?;

// Create tracks, call poll_events, etc...

// Open a file for writing
let mut file = OpenOptions::new()
    .write(true)
    .create(true)
    .truncate(true)
    .open("tracks.bin")
    .expect("Failed to open tracks.bin for writing");

// Save a snapshot of the client to a file for playback in release builds
let tracks = rocket.save_tracks();
bincode::encode_into_std_write(tracks, &mut file, bincode::config::standard())
    .expect("Failed to encode tracks.bin");
Source

pub fn set_row(&mut self, row: u32) -> Result<(), Error>

Send a SetRow message.

This changes the current row on the tracker side.

§Errors

This method can return an Error::IOError if Rocket tracker disconnects.

Source

pub fn poll_events(&mut self) -> Result<Option<Event>, Error>

Poll for new events from the tracker.

This polls from events from the tracker. You should call this fairly often your main loop. It is recommended to keep calling this as long as your receive Some(Event).

§Errors

This method can return an Error::IOError if the rocket tracker disconnects.

§Examples
while let Some(event) = rocket.poll_events()? {
    match event {
        // Do something with the various events.
        _ => (),
    }
}

Trait Implementations§

Source§

impl Debug for RocketClient

Source§

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

Formats the value using the given formatter. Read more

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.