CCashSession

Struct CCashSession 

Source
pub struct CCashSession { /* private fields */ }
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§

Source§

impl CCashSession

Source

pub fn new(base_url: &str) -> CCashSession

Constructs a new CCashSession from a base_url

Source

pub async fn establish_connection(&mut self) -> Result<(), CCashError>

Establishes a connection to the CCash instance using the session_url.

§Errors

Will return CCashError::CouldNotParsePropertiesResponse if the properties returned by CCash could not be parsed correctly.

Source

pub fn get_client(&self) -> &Option<Client>

Gets the client associated with this instance of CCashSession

Source

pub fn is_connected(&self) -> bool

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

Source

pub fn get_properties(&self) -> &Option<CCashSessionProperties>

Returns the properties of the CCash instance.

Trait Implementations§

Source§

impl Clone for CCashSession

Source§

fn clone(&self) -> CCashSession

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CCashSession

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.