Macro macro_state::append_state
source · [−]append_state!() { /* proc-macro */ }
Expand description
Like 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 append_state!
is also more efficient than re-writing an entire state file via write_state!
since the
low level append IO option is not used by write_state!
.
If no state file for the specified key
exists, it will be created automatically. In this
way, append_state!
functions similar to how init_state!
functions, especially in the
no-existing-file case.
Note that if read_state!
is called on an append_state!
-based state file, newlines
will be returned in the response.
Example
append_state!("my_key", "apples");
append_state!("my_key", "pears");
append_state!("my_key", "oh my!");
assert_eq!(read_state!("my_key"), "apples\npears\noh my!\n");