1 unstable release

0.1.0 Mar 15, 2020

#1185 in Database interfaces

MIT license

6KB
142 lines

recfiles & serde_rec

Manage GNU Recfiles from rust.

recfiles serde_rec

Installation

recfiles (in-memory recfile handling) & serde_rec (data format for serde) on crates.io.

Usage

use recfiles::Record;
use serde_rec::to_string;

#[derive(Default, Serialize)]
#[serde(rename_all="PascalCase")]
struct Book {
    author: Vec<String>,
    title: String,
    publisher: Option<String>,
}

impl Record for Book {}

let book = Book {
    author: vec![String::from("A.E.J. Eliott, OBE")],
    title: String::from("Thirty Days in the Samarkind Desert with the Duchess of Kent"),
    ..Default::default()
}

let serialised = to_string(&book).unwrap();

assert_eq!(serialised, textwrap::dedent("
    Author: A.E.J. Eliott, OBE
    Title: Thirty Days in the Samarking Desert with the Duchess of Kent

");

We can also specify the record descriptor for 'Book':

let book_descriptor = recfiles::Descriptor {
    name: String::from("Book"),
    key: vec![String::from("Title")],
    allowed: vec![String::from("Publisher"),
}

And serialise a full record set:

let rs = recfiles::RecordSet {
    descriptor: Some(book_descriptor),
    records: vec![book],
}

serde_rec::to_string(&rs);

Work in progress

This is a work in progress, and currently incomplete & poorly documented.

(As of writing, the above's all you're getting 😉.)

Coming...

  • Deserialisation
  • Deriving descriptors
  • File (rather than just to/from string) helpers
  • In-memory (not shelling out to recutils) querying helpers
  • Docs!

Dependencies

~0.4–1MB
~24K SLoC