Crate binroots

source ·
Expand description

binroots

Binroots is a (cross-platform!) crate that provides a simple and efficient way to save Rust data structures to disk. It allows you to save each field of a struct or enum variant as a separate file, making it easy to store reactive data, allowing end-users and hackers to watch individual files for changes and automate command-line tools for your app.

Setting up a struct - see binroots_struct

use binroots::binroots_struct;


#[binroots_struct]
struct Status {
    connections: usize,
    is_online: bool,
    activity: Activity,
}

Setting up an enum - see binroots_enum

use binroots::binroots_enum;

#[binroots_enum]
enum Activity {
    None, // <- Automatically chosen as the default value
    Playing(String),
}

Saving data - see Save::save and binroots_struct

#[binroots_enum]

use binroots::save::{RootType, SaveError};

fn main() -> Result<(), SaveError> {
    let mut status = Status::default();

    *status.is_online = true;
    status.save()?; // <- Saves the entire struct to the disk

    *status.activity = Activity::Playing("video gamb".into());
    status.activity.save(Status::ROOT_FOLDER, RootType::InMemory)?; // <- Only saves status.activity to the disk

    Ok(())
}

Modules

Traits

  • A data structure that can be serialized into any data format supported by Serde.

Attribute Macros

Derive Macros