pub fn proc_append_state(key: &str, value: &str) -> Result<()>
Expand description

An analogue for append_state! that should only be used within proc macros.

Like proc_write_state, but instead appends the specified value (newline-delimited) to the state file. Newlines contained in the value are automatically escaped so you can think of this as appending to a Vec<String> for all intents and purposes. Calling proc_append_state is also more efficient than re-writing an entire state file via proc_write_state since the low level append IO option is not used by proc_write_state.

If no state file for the specified key exists, it will be created automatically. In this way, proc_append_state functions similar to how proc_init_state functions, especially in the no-existing-file case.

Note that if proc_read_state is called on a proc_append_state-based state file, newlines will be returned in the response.

Examples

use macro_state::*;

proc_append_state("my_key", "apples");
proc_append_state("my_key", "pears");
proc_append_state("my_key", "oh my!");
assert_eq!(proc_read_state("my_key").unwrap(), "apples\npears\noh my!\n");
assert_eq!(proc_read_state_vec("my_key"), vec!["apples", "pears", "oh my!"]);