macro_rules! bincode { ($data:ty, $dir:expr, $project_directory:tt, $sub_directories:tt, $file_name:tt, $header:tt, $version:tt) => { ... }; }
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.
| Variable | Description | Related Trait Constant | Type | Example |
|---|---|---|---|---|
$data | Identifier of the data to implement for | struct or enum | State | |
$dir | Which OS directory to use | Bincode::OS_DIRECTORY | Dir | Dir::Data |
$project_directory | The name of the top project folder | Bincode::PROJECT_DIRECTORY | &str | "MyProject" |
$sub_directories | (Optional) sub-directories before file | Bincode::SUB_DIRECTORIES | &str | "some/dirs" |
$file_name | The file name to use | Bincode::FILE_NAME | &str | "state" |
$header | 24 custom byte header | Bincode::HEADER | [u8; 24] | [1_u8; 24] |
$version | 1 byte custom version | Bincode::VERSION | u8 | 5_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.