1 unstable release

0.1.0 Nov 27, 2023

#1439 in Rust patterns

MIT/Apache

33KB
790 lines

LSD

This is a Rust implementation of LSD (Less Syntax Data) configuration/data transfer format.

This is first implementation ever. If there ever will be any other implementations in this repository, they will most likely be a copy of this implementation.

Installation

Cargo/Crates

Main way of adding LSD to your Rust projects is via official crates.io repository.

Command

cargo add lsdata

Cargo.toml

Precise version (example; in case this README is not updated copy from crates.io page):

lsdata = "0.1.0"

Latest (for quick personal projects, not production):

lsdata = "*"

From GitHub

You may also let cargo build development LSD directly off of the GitHub branch.

Command

cargo add --git https://github.com/kirillsemyonkin/lsd.git

Cargo.toml

lsdata = { git = "https://github.com/kirillsemyonkin/lsd.git" }

From local folder

If you have a local variant you are working on, you may also refer to it instead.

Command

cargo add --path path/to/lsd/rust

Cargo.toml

lsdata = { path = "path/to/lsd/rust" }

Usage

Once you got LSD into your Rust project, import (use) it in your code:

use lsdata::LSD; // Just LSD enum itself
use lsdata::LSD::*; // LSD variants (LSD::Level, LSD::List, LSD::Value)
use lsdata::key; // `key!` macro
use lsdata::*; // Import everything directly into your scope (except those variants)

There is one parse method available for you:

let file_lsd = LSD::parse(File::open("example.lsd")?)?;
let string_lsd = LSD::parse(Cursor::new("example Hello world!"))?; 

To access values, it is useful to have key! macro ready:

let lang_key = "rust";
let lang_name = lsd
    .value(
        key!["languages" lang_key "name"],
        || LanguageNameIsNotAValue,
    )?
    .ok_or_else(|| CouldNotFindLanguageName)?;

Check out documentation to see more of the API.

Planned

  • Saving to a file
  • serde support

Dependencies

~1MB
~17K SLoC