Struct ccash_rs::CCashSession[][src]

pub struct CCashSession { /* fields omitted */ }
Expand description

Struct that describes the connection to the CCash API instance which is defined by the session_url.

Usage

The intended usage for this struct is to provide a simple way to connect to the CCash instance and be passed into the functions provided by methods and methods::admin. This also means multiple CCashSessions can be connected to different CCash instances, if need be.

An example usage is as follows (available here):

#![allow(unused_assignments)]

use ccash_rs::*;
use std::io::{self, prelude::*};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    print!("Please enter the instance URL > ");
    io::stdout().flush().unwrap();
    let mut instance_url = String::new();
    match io::stdin().read_line(&mut instance_url) {
        Ok(v) => v,
        Err(e) => panic!("{}", e),
    };
    instance_url = instance_url.trim().to_string();
    io::stdout().flush().unwrap();

    print!("Please enter your username > ");
    io::stdout().flush().unwrap();
    let mut name = String::new();
    match io::stdin().read_line(&mut name) {
        Ok(v) => v,
        Err(e) => panic!("{}", e),
    };
    name = name.trim().to_string();
    io::stdout().flush().unwrap();

    let user = match CCashUser::new(&name, &"") {
        Ok(user) => user,
        Err(error) => panic!("{}", error),
    };

    let mut session = CCashSession::new(&instance_url);
    session.establish_connection().await.expect("{}");
    println!(
        "Balance: {}",
        methods::get_balance(&session, &user).await.expect("{}")
    );
    Ok(())
}

Before any function from methods and methods::admin is called, establish_connection must be called to make sure that the connection to the CCash instance is secured and correct. This also makes sure that the properties of CCashSession is properly set and not None.

Implementations

Constructs a new CCashSession from a base_url

Establishes a connection to the CCash instance using the session_url.

Gets the client associated with this instance of CCashSession

Returns whether or not the CCashSession is connectd to the instance.

Returns the properties of the CCash instance.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.