2 releases
new 0.1.1 | Mar 17, 2025 |
---|---|
0.1.0 | Mar 9, 2025 |
#60 in #config
203 downloads per month
67KB
1.5K
SLoC
Simple Records

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::*;
- Read a document.
let doc = Document::read("whitelist") // reads from whitelist.rules
- Create a search filter for
* '127.0.0.1' *
.
let filter = Filter::new("whitelist", &[None, Some("127.0.0.1"), None])
- Run the search.
let found = doc.find(filter);
- 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
Type | Description |
---|---|
char | A single character |
i8 | An integer value between -128 and 127 |
u8 | An integer value between 0 and 255 |
i16 | An integer value between -32k and 32k |
u16 | An integer value between 0 and 65k |
i32 | An integer value between -2.1B and 2.1B |
u32 | An integer value between 0 and 4.2B |
i64 | You get the idea |
u64 | You get the idea |
f32 | 32 bit floating number. |
f64 | 64 bit floating number. |
istr | Case sensitive string. |
ustr | Case insensitive string. |
bool | Boolean 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", *])