disk

Macro bincode

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

Implement the Bincode trait

File extension is bin and is automatically appended.

§Input

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

VariableDescriptionRelated Trait ConstantTypeExample
$dataIdentifier of the data to implement forstruct or enumState
$dirWhich OS directory to useBincode::OS_DIRECTORYDirDir::Data
$project_directoryThe name of the top project folderBincode::PROJECT_DIRECTORY&str"MyProject"
$sub_directories(Optional) sub-directories before fileBincode::SUB_DIRECTORIES&str"some/dirs"
$file_nameThe file name to useBincode::FILE_NAME&str"state"
$header24 custom byte headerBincode::HEADER[u8; 24][1_u8; 24]
$version1 byte custom versionBincode::VERSIONu85_u8

§Example

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

const HEADER: [u8; 24] = [1_u8; 24];
const VERSION: u8 = 5;

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

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