Struct NotAuthenticatedClient

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

A connected but not yet authenticated RCON client.

Clients must successfully authenticate before sending commands and receiving logs, which is enforced by this type.

To make an authentication attempt, use authenticate.

§Example

use northstar_rcon_client::connect;

#[tokio::main]
async fn main() {
    let client = connect("localhost:37015")
        .await
        .unwrap();

    match client.authenticate("password123").await {
        Ok(_) => println!("Authentication successful!"),
        Err((_, err)) => println!("Authentication failed: {}", err),
    }
}

Implementations§

Source§

impl NotAuthenticatedClient

Source

pub async fn authenticate( self, pass: &str, ) -> Result<(ClientRead, ClientWrite), (NotAuthenticatedClient, AuthError)>

Attempt to authenticate with the RCON server.

If the authentication attempt is successful this client will become a ClientRead/ClientWrite pair, allowing executing commands and reading log lines.

If authentication fails the function will return the reason, as well as the client to allow repeated authentication attempts.

§Example
use std::io::BufRead;
use northstar_rcon_client::connect;

#[tokio::main]
async fn main() {
    let mut client = connect("localhost:37015")
        .await
        .unwrap();

    let mut lines = std::io::stdin().lock().lines();

    // Keep reading passwords until authentication succeeds
    let (read, write) = loop {
        print!("Enter password: ");
        let password = lines.next()
            .unwrap()
            .unwrap();

        match client.authenticate(&password).await {
            Ok((read, write)) => break (read, write),
            Err((new_client, err)) => {
                println!("Authentication failed: {}", err);
                client = new_client;
            }
        }
    };
}

Trait Implementations§

Source§

impl Debug for NotAuthenticatedClient

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.