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 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
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
Auto Trait Implementations
impl !RefUnwindSafe for CCashSession
impl Send for CCashSession
impl Sync for CCashSession
impl Unpin for CCashSession
impl !UnwindSafe for CCashSession
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more