Macro disk::postcard

source ·
macro_rules! postcard {
    ($data:ty, $dir:expr, $project_directory:tt, $sub_directories:tt, $file_name:tt) => { ... };
}
Expand description

Implement the Postcard trait

File extension is bin and is automatically appended.

Input

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

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

Example

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

postcard!(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.bin.