crypt-configs 0.2.0

A modern config file format
Documentation

Crypt Configuration files

A modern readable file format.

Crypt files are similar to json with additional support for enums special tags, identifiers, and includes. Crypt is essentially a superset of json meaning any json file can parsed as if it was a crypt file. Using the beauty of Rust crypt files can be parsed directly into rust native structs and enums using the Cryptic derivation.

Why did I make Crypt

tbh idk

Example crypt file

name = "John doe",
age: 34,
"description": "An unkown patient",

Most notably : and = can both be used to show ownership. Identifiers and strings can both be used interchangeably to represent an owner. Unlike json the main {...} can be ignored but will automatically be promoted to the main body if present.

{
  objects: {
    "can": {
      be: {
        nested: ["indefinitely"]
      }
    }
  }
}

Crypt also has special tags that can be added to a file. Tags come in two valid formats.

#format=A
"format a": {
  
},

#(format=B, more)
"format B": {

}

Using #(...) allows for multiple tags. If an object only expects on tag but and this syntax is used it will only consume the first item.

Loading a crypt file

To parse a crypt file a CryptParserServer is used which automatically caches opened files and reuses them when requested.

use crypt_config::{CryptParserServer, Cryptic};

// The Crypt macro will automatically implement
// conversion from a crypt file.
#[derive(Debug, Cryptic)]
struct Person {
    // A default value can be provided.
    // This value must be obtainable via the 
    // String::parse method.
    #[default_value="John doe"]
    name: String,

    // Values that aren't optional or are 
    // provided a default value will trigger 
    // a parsing error if not found within the file.
    age: u32,

    // Object of type Option can be
    // marked as optional to automatically 
    // set their value to None if not found.
    #[optional]
    desc: Option<String>,

    // The Tagged type is used to consume any 
    // special tags. This only supports single tags. 
    // For lists of tags and maps of tags ListTagged and HashTagged are available.
    tagged: Tagged<String, String>,
}

let mut server = CryptParserServer::new();

let my_person: Person = server.open("path/to/my/file.crypt")?;

Enum Objects

Special tags also have the benefit of being able to tell the variant of an enum. Crypt derive macro is also available for enums and require the type to be tagged with the variant and it will do the rest.

#[derive(Cryptic)]
enum CrypticResult {
    Ok(String),
    Err {
        message: String,
    },
    Undefined
}

Now creating the type in crypt:

ok_result: #Ok "Perfect",
err_result: #Err { message: "Failed to to something" },
undefined_result: #Undefined[],

The object after the tag will automatically be converted into the arguments of the variant. Regardless an object must be present following the tag for it to be valid.

ok_result: #Ok 30,
err_result: #Err message: null,
undefined_result: #Undefined null,

Include other files

The !import keyword can be used to import objects from other crypt of json files.

my_obj: {
  A: "something",
  B: !import "path/to/other.crypt"
}

Working on:

There are a few additions that are planned for future versions.

Comments

As of right not crypt has no form of comments. It is likely that the > will be used to mark a comment.

Rust -> Crypt

Crypt can be easily converted into Rust structs but Rust structs can't be formatted into Crypt files. This will likely be implemented similar to Cryptic and will be called Cryptograph.