Crate koit_toml[][src]

Expand description

Koit is a simple, asynchronous, pure-Rust, structured, embedded database.

Examples

use std::default::Default;

use koit::{FileDatabase, format::Toml};
use serde::{Deserialize, Serialize};

#[derive(Default, Deserialize, Serialize)]
struct Data {
    cats: u64,
    yaks: u64,
}

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db = FileDatabase::<Data, Toml>::load_from_path_or_default("./db.toml").await?;
   
    db.write(|data| {
        data.cats = 10;
        data.yaks = 32;
    }).await;
     
    assert_eq!(db.read(|data| data.cats + data.yaks).await, 42);

    db.save().await?;

    Ok(())
}

Features

Koit comes with a file-backed database and JSON and Bincode formatters. You can also define your own storage format or backend.

Note that the file-backed database requires the Tokio 0.3 runtime to function.

Re-exports

pub use backend::Backend;
pub use format::Format;

Modules

backend

Backends persist the database. They allow reading and writing bytes. Bytes-to-data conversion, and back, is handled by a Format.

format

Formats handle transforming structured data to and from bytes for persisting.

Structs

Database

The Koit database.

Enums

KoitError

The error variants Koit can return.

Type Definitions

FileDatabasefile-backend

A file-backed database.