Expand description

Helper to store persistent or temporary data to disk.

This module provides methods to store workflow related data (such as settings, configurations, …) to disk. Additionally using the non-method functions workflow authors can save/load data to workflow’s cache directory.

To store/retrieve workflow related data, use set() and get() method after load()ing. Example of such data can be authentication info related to workflow or how many items you should show to user in Alfred’s main window.

To save/load temporary data, use save_to_file() and load_from_file() functions. Example of such data are cached list of items related to workflow or a downloaded file to be used later.

Example

extern crate chrono;
use alfred_rs::data::Data;

// Load the workflow data (or create a new one)
let mut workflow_data = Data::load("settings.json").unwrap();

// Set *and* save key/value `user_id: 0xFF` pair
workflow_data.set("user_id", &0xFF);

// We can set/save different data types.
// For example, set and save timestamp of last use of workflow:
workflow_data.set("last_use_date", &Utc::now());


// Later on, you can retreive the values:
let last_use: DateTime<Utc> =
    workflow_data.get("last_use_date").expect("timestamp was not set");

// Additioanlly, you can save temporary data to workflow's cache folder:
Data::save_to_file("all_my_tweets.cache", &vec!["chirp1", "chirp2"]).unwrap();

See Data’s documentation for more examples.

Structs

Workflow data that will be persisted to disk