16 releases

0.5.8 Aug 30, 2024
0.5.7 Jul 23, 2024
0.5.5 Aug 30, 2023
0.5.3 Dec 16, 2021
0.1.3 Jun 6, 2018

#367 in Encoding

Download history 725/week @ 2024-07-22 467/week @ 2024-07-29 707/week @ 2024-08-05 538/week @ 2024-08-12 524/week @ 2024-08-19 610/week @ 2024-08-26 399/week @ 2024-09-02 477/week @ 2024-09-09 420/week @ 2024-09-16 327/week @ 2024-09-23 228/week @ 2024-09-30 478/week @ 2024-10-07 499/week @ 2024-10-14 469/week @ 2024-10-21 655/week @ 2024-10-28 587/week @ 2024-11-04

2,218 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–8MB
~81K SLoC