No description
  • Rust 99.6%
  • Nix 0.4%
Find a file
2021-02-12 19:04:59 +01:00
.github/workflows ci 2020-12-02 00:32:21 +01:00
benches also optimize single quoted strings 2020-12-08 21:36:08 +01:00
examples serde example 2020-12-14 00:13:00 +01:00
src add as_int/float to Value 2021-02-12 19:04:59 +01:00
tests finish serde support 2020-12-14 00:11:32 +01:00
.gitignore init repo 2020-12-01 17:44:52 +01:00
Cargo.toml finish serde support 2020-12-14 00:11:32 +01:00
README.md finish serde support 2020-12-14 00:11:32 +01:00

php-literal-parser

parser for php literals.

Usage

Parse into a generic representation

use php_literal_parser::{from_str, Value, ParseError};

fn main() -> Result<(), ParseError> {
    let map = from_str::<Value>(r#"["foo" => true, "nested" => ['foo' => false]]"#)?;

    assert_eq!(map["foo"], true);
    assert_eq!(map["nested"]["foo"], false);
    
    Ok(())
}

Or parse into a specific struct using serde

use php_literal_parser::{from_str, ParseError};
use serde::Deserialize;

#[derive(Debug, Deserialize, PartialEq)]
struct Target {
    foo: bool,
    bars: Vec<u8>
}

fn main() -> Result<(), ParseError> {
    let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4,]]"#)?;

    assert_eq!(Target {
        foo: true,
        bars: vec![1, 2, 3, 4]
    }, target);
    Ok(())
}