disk

Macro bincode2

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

Implement the Bincode2 trait

File extension is bin and is automatically appended.

§Input

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

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

§Example

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

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

bincode2!(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.