// Initializes the store from the local json file on start-up.
Initializes the store from the local json file on start-up.
Initializes the store from the local json file on start - up .
pub fn initialize_store_from_file(path: String) -> Result<String, String> {
    if !Path::new(&format!("{}/store.json", path)).exists() {
        return Ok("No persistent file available.".to_string());
    }
    let json_string = match read_persistent_store_file_to_string(path) {
        Ok(json) => json,
        Err(e) => return Err(format!("Could not read persistent data file: {}", e)),
    };
    let v: HashMap<String, String> = match serde_json::from_str(json_string.as_str()) {
        Ok(val) => val,
        Err(e) => return Err(format!("Could not parse json: {}", e)),
    };
    // for each element in array
    STORE.write().unwrap().elements = v;
    // insert element in store
    Ok("Loaded store from file.".to_string())
}
pub fn initialize_store_from_file ( path : String ) -> Result < String , String > { if ! Path :: new ( & format ! ( " " path ) ) . exists ( ) { return Ok ( " " . to_string ( ) ) ; } let json_string = match read_persistent_store_file_to_string ( path ) { Ok ( json ) => json , Err ( e ) => return Err ( format ! ( " " e ) ) , } ; let v : HashMap < String , String > = match serde_json :: from_str ( json_string . as_str ( ) ) { Ok ( val ) => val , Err ( e ) => return Err ( format ! ( " " e ) ) , } ; // for each element in array STORE . write ( ) . unwrap ( ) . elements = v ; // insert element in store Ok ( " " . to_string ( ) ) }
Initializes the store from the local json file on start-up.
Initializes the store from the local json file on start - up .
path
String