pub trait Session {
// Required methods
async fn login(&self) -> Result<String>;
fn set_credentials(&mut self, password: &str) -> Result<()>;
fn session_id_file(&self) -> &str;
fn secret(&self) -> Secret;
fn retry(&self) -> i32;
fn inc_retry(&mut self);
fn reset_retry(&mut self);
// Provided methods
async fn get_session_id(&mut self) -> Result<String> { ... }
fn read_session_id(file_name: &str) -> Result<String> { ... }
fn write_session_id(file_name: &str, session_id: &str) -> Result<()> { ... }
fn delete_session_id(&self) -> Result<()> { ... }
}Expand description
Session lifecycle shared by every API client: cache the session id on disk, prompt for the password only when needed, retry a bounded number of times.
Implementors supply the provider-specific pieces (login,
set_credentials, file names); the provided methods do the rest.
Required Methods§
Sourceasync fn login(&self) -> Result<String>
async fn login(&self) -> Result<String>
Authenticates with the stored credentials, returning a session id.
Sourcefn set_credentials(&mut self, password: &str) -> Result<()>
fn set_credentials(&mut self, password: &str) -> Result<()>
Stores the password (encoded as the provider requires) for login.
Sourcefn session_id_file(&self) -> &str
fn session_id_file(&self) -> &str
Per-provider session cache filename.
Sourcefn reset_retry(&mut self)
fn reset_retry(&mut self)
Clears the failed-attempt count after a successful login.
Provided Methods§
Sourceasync fn get_session_id(&mut self) -> Result<String>
async fn get_session_id(&mut self) -> Result<String>
Returns a session id: cached if available, otherwise via login with
up to [MAX_RETRY_COUNT] password attempts (a retry always
re-prompts rather than reusing a password that just failed).
Sourcefn read_session_id(file_name: &str) -> Result<String>
fn read_session_id(file_name: &str) -> Result<String>
Reads the cached session id.
Sourcefn write_session_id(file_name: &str, session_id: &str) -> Result<()>
fn write_session_id(file_name: &str, session_id: &str) -> Result<()>
Writes the session id to the cache file.
Sourcefn delete_session_id(&self) -> Result<()>
fn delete_session_id(&self) -> Result<()>
Drops the cached session, forcing a fresh login next time.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".