14 releases

0.5.5 Aug 30, 2023
0.5.3 Dec 16, 2021
0.5.1 Oct 9, 2020
0.5.0 May 15, 2020
0.1.3 Jun 6, 2018

#180 in Encoding

Download history 300/week @ 2024-01-02 532/week @ 2024-01-09 321/week @ 2024-01-16 396/week @ 2024-01-23 378/week @ 2024-01-30 543/week @ 2024-02-06 483/week @ 2024-02-13 659/week @ 2024-02-20 501/week @ 2024-02-27 414/week @ 2024-03-05 467/week @ 2024-03-12 430/week @ 2024-03-19 414/week @ 2024-03-26 428/week @ 2024-04-02 424/week @ 2024-04-09 467/week @ 2024-04-16

1,781 downloads per month
Used in 2 crates

Apache-2.0

385KB
5.5K SLoC

flatdata-rs latest version docs

Write-once, read-many, minimal overhead binary structured file format.

Flatdata is a library providing data structures for convenient creation, storage and access of packed memory-mappable structures with minimal overhead.

With flatdata, the user defines a schema of the data format using a very simple schema language that supports plain structs, vectors and multivectors. The schema is then used to generate builders and readers for serialization and deserialization of the data to an archive of files on disk.

The data is serialized in a portable way which allows zero-overhead random access to it by using memory mapped storage: the operating system facilities are used for loading, caching and paging of the data, and most important, accessing it as if it were in memory.

Example

The folder tests/coappearances contains a graph of character coappearances in Tolstoi's Anna Karenina as flatdata archive schema together with the serialized data. The standalone tests read and write all different types of data and check that the data was de/serialized correctly.

Getting started

We recommend that you use a build.rs to automatically generate the code from your flatdata schema.

// build.rs
fn main() {
    flatdata::generate(
        "path/to/my_schema.flatdata",
        &std::env::var("OUT_DIR").unwrap(),
    )
    .expect("generator failed");
}

Then add a module to your crate and include the generated code:

#![allow(dead_code)]
include!(concat!(env!("OUT_DIR"), "path/to/my_schema.rs"));
// re-export if desired
pub use my_schema::*;

See the documentation of generator.rs for a more detailed explaination.

Dependencies

~0.3–9.5MB
~80K SLoC