pub struct RocketClient { /* private fields */ }
Expand description
The RocketClient
type. This contains the connected socket and other fields.
Implementations§
Source§impl RocketClient
impl RocketClient
Sourcepub fn new() -> Result<Self, Error>
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()?;
Sourcepub fn connect(addr: impl ToSocketAddrs) -> Result<Self, Error>
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))?;
Sourcepub fn get_track_mut(&mut self, name: &str) -> Result<&mut Track, Error>
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);
Sourcepub fn get_track(&self, name: &str) -> Option<&Track>
pub fn get_track(&self, name: &str) -> Option<&Track>
Get track by name.
You should use get_track_mut
to create a track.
Sourcepub fn save_tracks(&self) -> &Tracks
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");
Sourcepub fn set_row(&mut self, row: u32) -> Result<(), Error>
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.
Sourcepub fn poll_events(&mut self) -> Result<Option<Event>, Error>
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.
_ => (),
}
}