Crate simplerecords

Crate simplerecords 

Source
Expand description

§Simple Records   Latest Version Downloads Stars

Strongly typed text-based format for declarative configuration.

[dependencies]
simplerecords = "0.1"

Here are some reasons to use Simple Records.

  • Human readable. For large number of rules, records can be written in a table-like format.
  • Performant searching. All records are indexed to be ready for search.
  • Multi-file support. Records and definitions can be imported from any file for maximum flexibility.

§Format specification

Comments are ignored.

  • Single line: #
  • Multi-line: /* */
#               username    IP          expiry

Definition define the record type.

#               v--- unsigned string    v--- 64 bit unsigned integer
whitelist:      ustr        istr        u64
#                           ^--- signed string

Record has a type and fields.

whitelist       joe         127.0.0.1   123456
whitelist       bob         127.0.0.1   123457
whitelist       alice       127.0.0.3   123459

Import additional rule files.

include filename

The default file extension if none specified, is *.rules.

Definition and rules can be in any file and in any order, as long as it exists.

§Usage

use simplerecords::*;
  1. Read a document.
let doc = Document::read("whitelist") // reads from whitelist.rules
  1. Create a search filter for * '127.0.0.1' *.
let filter = Filter::new("whitelist", &[None, Some("127.0.0.1"), None])
  1. Run the search.
let found = doc.find(filter);
  1. Output the results.
(whitelist@3) whitelist "joe" "127.0.0.1" 123456
(whitelist@4) whitelist "bob" "127.0.0.1" 123457

§Multiple imports

You can read a single document from multiple files.

let doc = Options::default()
    // specify files to load from
    .with("include users")
    .with("include permissions")
    .open();

§Scoping

Sections of the file can be labelled for organisation.

scope friends   # joe and bob are in the 'friends' scope
whitelist       joe         127.0.0.1   123456
whitelist       bob         127.0.0.1   123457

scope members   # alice is in the 'members' scope
whitelist       alice       127.0.0.3   123459

scope           # reset scopes
whitelist       sirius      127.0.0.5   123451

The examples above can be found in src/examples.

§Types

TypeDescription
charA single character
i8An integer value between -128 and 127
u8An integer value between 0 and 255
i16An integer value between -32k and 32k
u16An integer value between 0 and 65k
i32An integer value between -2.1B and 2.1B
u32An integer value between 0 and 4.2B
i64You get the idea
u64You get the idea
f3232 bit floating number.
f6464 bit floating number.
istrCase sensitive string.
ustrCase insensitive string.
boolBoolean value.

§Todo

All current features are stable and there will be no breaking changes.

New features will be added until this becomes a text-based database. Including

  • Insert/delete/amending records.
  • Value constraints
  • Filter macro for more concise syntax.
doc.filter(filter![*, "127.0.0.1", *])

Structs§

Document
Represents a parsed simplerecords document
Filter
Represents a search query.
Options
Represents options when opening a Document
Pass
Splits a file input into two streams.
Record
Represents a single record.
RecordSet
Represents all records of the same type.
Schema
Represents all the type definitions
SchemaOne
Represents a single type definition.

Enums§

Error
Represents all possible errors that can occur.
Field
Represents a typed field in a record.
ParseError
Represents all possible errors that can occur while parsing from file.
Signature
Type signatures.