https://github.com/daksh14/rtoml
RToml is an experimental 100% handwritten toml parser
https://github.com/daksh14/rtoml
parser rust toml
Last synced: about 1 year ago
JSON representation
RToml is an experimental 100% handwritten toml parser
- Host: GitHub
- URL: https://github.com/daksh14/rtoml
- Owner: Daksh14
- License: mit
- Created: 2020-09-09T10:42:38.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2022-08-02T10:50:49.000Z (almost 4 years ago)
- Last Synced: 2025-06-14T18:08:49.768Z (about 1 year ago)
- Topics: parser, rust, toml
- Language: Rust
- Homepage:
- Size: 3.79 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rtoml
Rtoml is a toml parser that's designed to
1. Acquire values at compile time to a struct.
2. Acquire values at runtime required to work.
At the core, a Toml value is represented by this enum
```rust
pub enum TomlValue<'a> {
Int(i64),
Float(f64),
String(String),
Array(Vec>),
Boolean(bool),
DateTime(DateTime),
Table(Table<'a>),
}
```
# Usage
For a toml file
```toml
[a_table]
value = "hello, world"
```
We will use the following code to acquire values
```rust
use rtoml::prelude::*;
use std::error::Error;
fn main() -> Result<(), TomlError> {
let mut data = String::new();
let mut file = File::open(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/test.toml"))?;
file.read_to_string(&mut data)?;
let toml = TomlValue::try_from(data.as_str())?;
if let Some(table) = toml.as_table() {
if let Some(key_value) = table.get(&TomlKey::from("a_table")) {
assert_eq!(key.get(
TomlKey::from("value"),
TomlValue::Literal(String::from("hello, world"))
))
}
}
Ok(())
}
```
# Benchmarks
```
cargo bench
open ./target/criterion/report/index.html
```
# TODO
- [ ] Table dot `.` format in table names
- [ ] Table arrays
- [ ] Serialise derive traits
- [ ] Use toml testing repo to run all tests
# License
MIT