Error saving with Preferences crate


#1

I am using the Preferences crate to save some app configuration data. No matter what value I use for “key” it fails. Not much output to help me understand why. Does anyone know how to make this work?

Code:

use preferences::{AppInfo, PreferencesMap, Preferences};

#[test]
fn save_config_file() {
    let APPINFO = AppInfo{name: "preferences", author: ""};
    let config_location = "config/solid";
    // these values also fail
    // let config_location = "config";
    // let config_location = "~/config"

    let mut data: PreferencesMap<String> = PreferencesMap::new();
    data.insert("data_source".to_string(), "memory".to_string());
    data.insert("computation".to_string(), "max".to_string());
    data.insert("pay_this_amount".to_string(), "13".to_string());

    let save_result = data.save(&APPINFO, config_location);
    assert!(save_result.is_ok());
}

Error:
panicked at 'assertion failed: save_result.is_ok()'

Thnx
Matt


#2

What’s the output of println!("{:?}", save_result)?


#3

I got this as a result of the println!:

result of save is: Err(Directory(InvalidAppInfo))

so I changed the AppInfo structure data to the following

let APPINFO = AppInfo{name: "preferences", author: "999999"};

I no longer get an error. The println output is:

result of save is: Ok(())

BUT, I cannot find a file with data…anywhere. I have looked in my project target/debug directory. I looked in my home directory. I looked in root. Nothing.

So it says it saved, but where?

Thnx
Matt


#4

Try their fn to discover the base directory.


#5

oh. That’s ugly, at least for my needs.

Thnx
Matt