Giter Site home page Giter Site logo

recfiles-rs's Introduction

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!

recfiles-rs's People

Contributors

ojford avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

zaxebo1 zeerooth

recfiles-rs's Issues

Implement descriptor derivation

Instead of having to create a descriptor like:

let descriptor = recfiles::Descriptor {
    name: String::from("MyRecordType"),
    // etc.
};

we should be able to derive the basics from a struct that implements Record.

Of course not everything, we can't know what's a %key for example, but we can infer mandatory & allowed fields, and the name.

Add methods for sanitising & reading field properties

If a field is mandatory, it doesn't need to be specified as allowed (for example). We should add a method for sanitising such properties of field names into a canonical form.

It can be useful though to know all allowed field names, without having to dig through each property which makes them implicitly allowed. We should have methods for retrieving field names by property (allowed/prohibited/unique/key/mandatory/anything I've forgotten) regardless of whether explicit or implicit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.