disk

Macro json

Source
macro_rules! json {
    ($data:ty, $dir:expr, $project_directory:expr, $sub_directories:expr, $file_name:expr) => { ... };
}
Available on crate feature json only.
Expand description

Implement the Json trait

File extension is json and is automatically appended.

§Input

These are the inputs you need to provide to implement Json.

VariableDescriptionRelated Trait ConstantTypeExample
$dataIdentifier of the data to implement forstruct or enumMyState
$dirWhich OS directory to useJson::OS_DIRECTORYDirDir::Data
$project_directoryThe name of the top project folderJson::PROJECT_DIRECTORY&str"MyProject"
$sub_directories(Optional) sub-directories before fileJson::SUB_DIRECTORIES&str"some/dirs"
$file_nameThe file name to useJson::FILE_NAME&str"state"

§Example

use serde::{Serialize,Deserialize};
use disk::*;

json!(State, Dir::Data, "MyProject", "some/dirs", "state");
#[derive(Serialize,Deserialize)]
struct State {
    string: String,
    number: u32,
}

This example would be located at ~/.local/share/myproject/some/dirs/state.json.