Struct mc_query::rcon::RconClient

source ·
pub struct RconClient { /* private fields */ }
Expand description

Struct that stores the connection and other state of the RCON protocol with the server.

Examples

use mc_query::rcon::RconClient;
use tokio::io::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = RconClient::new("localhost", 25575).await?;
    client.authenticate("password").await?;

    let output = client.run_command("time set day").await?;
    println!("{output}");

    Ok(())
}

Implementations§

source§

impl RconClient

source

pub async fn new(host: &str, port: u16) -> Result<Self>

Construct an RconClient that connects to the given host and port. Note: to authenticate use the authenticate method, this method does not take a password.

Arguments
  • host - A string slice that holds the hostname of the server to connect to.
  • port - The port to connect to.
source

pub async fn disconnect(self) -> Result<()>

Disconnect from the server and close the RCON connection.

source

pub async fn authenticate(&mut self, password: &str) -> Result<()>

Authenticate with the server, with the given password.

If authentication fails, this method will return RconProtocolError::AuthFailed.

Arguments
  • password - A string slice that holds the RCON password.
source

pub async fn run_command(&mut self, command: &str) -> Result<String>

Run the given command on the server and return the result.

Arguments
  • command - A string slice that holds the command to run. Must be ASCII and under 1446 bytes in length.

Trait Implementations§

source§

impl Debug for RconClient

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V