Crate php_literal_parser
source ·Expand description
Parser for php literals.
Allows parsing of php string, bool, number and array literals.
§Usage
Parse into a generic representation
use php_literal_parser::{from_str, Value};
let map = from_str::<Value>(r#"["foo" => true, "nested" => ['foo' => false]]"#)?;
assert_eq!(map["foo"], true);
assert_eq!(map["nested"]["foo"], false);
Or parse into a specific struct using serde
use php_literal_parser::from_str;
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct Target {
foo: bool,
bars: Vec<u8>
}
let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4,]]"#)?;
assert_eq!(Target {
foo: true,
bars: vec![1,2,3,4]
}, target);
Enums§
- A php array key, can be either an int or string
- Any error that occurred while trying to parse the php literal
- A php value, can be either a bool, int, float, string, an array or null
Functions§
- Parse a php literal