Struct alfred_rs::data::Data [] [src]

pub struct Data { /* fields omitted */ }

Workflow data that will be persisted to disk

Methods

impl Data
[src]

[src]

Loads the workflow data or creates a new one.

Reads the content of workflow's standard data file WORKFLOW_UID-persistent-data.json. If the file is missing or corrupt a new (empty) data will be produced.

Errors:

This method can fail if any disk/IO error happens.

[src]

Set the value of key k to v and persist it to disk

k is a type that implements Into<String>. v can be any type as long as it implements Serialize.

This method overwrites values of any existing keys, otherwise adds the key/value pair to the workflow's data 'stash'

Example

use alfred_rs::data::Data;

let mut workflow_data = Data::load().unwrap();

workflow_data.set("user_id", 0xFF);
workflow_data.set("last_log_date", Utc::now());

Errors:

If v cannot be serialized or there are file IO issues an error is returned.

[src]

Get (possible) value of key k from workflow's data file

If key k has not been set before None will be returned.

Since the data can be of arbitrary type, you should annotate the type you are expecting to get back from data file. If the stored value cannot be deserialized back to the desired type None is returned.

Example

use alfred_rs::data::Data;

let wf_data = Data::load().unwrap();

let id: i32 = wf_data.get("user_id").expect("user id was not set");
let last_log: DateTime<Utc> = wf_data.get("last_log_date").expect("log date was not set");

[src]

Function to save (temporary) data to file named p in workflow's cache dir

This function is provided so that workflow authors can temporarily save information to workflow's cache dir. The saved data is considered to be irrelevant to workflow's actual data (for which you should use set and get)

Example

use alfred_rs::data::Data;

Data::save_to_file("cached_tags.dat", vec!["rust", "alfred"]).unwrap();

Note

Only the file_name portion of p will be used to name the file in workflow's cache directory.

Errors

File IO related issues as well as serializing problems will cause an error to be returned.

[src]

Function to load some (temporary) data from file named p in workflow's cache dir

This function is provided so that workflow authors can retrieve temporarily information saved to workflow's cache dir. The saved data is considered to be irrelevant to workflow's actual data (for which you should use set and get)

Example

use alfred_rs::data::Data;

let cached_tags: Vec<String> = Data::load_from_file("cached_tags.dat").unwrap();

Note

Only the [file_name] portion of p will be used to name the file in workflow's cache directory.

Trait Implementations

impl Debug for Data
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Data

impl Sync for Data