Hi,
I am new to rust and am trying to implement a singleton as a static method which returns a reference to a trait.
pub mod Auth {
use chrono::{DateTime, Utc};
use md5;
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::RwLock;
lazy_static! {
static ref ai: Arc<dyn AuthInterface> = Arc::new(AuthImpl::new());
}
pub trait AuthInterface {
fn register_user(&self, email: &str, pwd: &str) -> String;
}
pub fn getAuthInterface() -> Arc<dyn AuthInterface> {
/ getting an error here -
// mismatched types - expected struct `std::sync::Arc`, found struct `ims::Auth::ai`
return ai;
}
struct AuthImpl {
usr_record_store: RwLock<HashMap<String, String>>,
}
impl AuthInterface for AuthImpl {
fn register_user(&self, email: &str, pwd: &str) -> String {
return String::from("");
}
}
impl AuthImpl {
pub fn new() -> AuthImpl {
AuthImpl {
usr_record_store: RwLock::new(HashMap::new()),
}
}
}
How can i have a singleton static method that returns a trait