Skip to content

Djalcoding/dparser.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dparser.rs

A Rust library for parsing configuration files

!! This is documentation. 
  !! This is a number
number1: 12.643
  !! This is also a number
number2: -12
  !! This is a color as an rgb string
color1: (0,255,0)
  !! This is a color as an hexadecimal color
color2: #FFFFFF
  !! This is a color represented with a name
color3: red
  !! This is text
text: "Lorem Ipsum"
  !! Those is are booleans
bool1 = yes
bool2 = y
bool2 = true
bool3 = 1 !! Note that this doesn't work for every number, only 1
bool1 = no
bool2 = n
bool2 = false
bool3 = 0

Usage

Retrieving data

Using dparser is quite simple. the library provides you a HashMap wrapper to retrieve the data present associated with a given key inside of the configuration file : ParsedData.

It also allows you to interpret the data as 4 different datatype :

  • bool
  • String
  • f64
  • Color, a struct provided by the library that represents an rgb color and does hexadecimal conversion for you.

Error handling

if the library fails to parse your file, or interpret a datatype, you are provided with two new error types that give you access to the error message, the file where the error happened and (optionally) the line where the error happenned.

Adding this library to your project

Thanks to cargo, adding dparser to your project is as easy as ever :

cargo add djal_parser

Notes

for more information on how to make files or use the library, go check the documentation on [https://docs.rs/djal_parser/0.1.0/djal_parser/]

About

A Rust library for parsing configuration files

Resources

Stars

Watchers

Forks

Languages