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 CCashSession
s
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
impl CCashSession
Sourcepub fn new(base_url: &str) -> CCashSession
pub fn new(base_url: &str) -> CCashSession
Constructs a new CCashSession
from a base_url
Sourcepub async fn establish_connection(&mut self) -> Result<(), CCashError>
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.
Sourcepub fn get_client(&self) -> &Option<Client>
pub fn get_client(&self) -> &Option<Client>
Gets the client associated with this instance of CCashSession
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns whether or not the CCashSession
is connectd to the instance.
Sourcepub fn get_properties(&self) -> &Option<CCashSessionProperties>
pub fn get_properties(&self) -> &Option<CCashSessionProperties>
Returns the properties of the CCash
instance.
Trait Implementations§
Source§impl Clone for CCashSession
impl Clone for CCashSession
Source§fn clone(&self) -> CCashSession
fn clone(&self) -> CCashSession
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more