Skip to main content

parse_ref

Function parse_ref 

Source
pub fn parse_ref<'a>(
    text: &'a str,
    arena: &'a Bump,
) -> Result<ValueRef<'a>, SyntaxError>
Expand description

Parses text straight to a borrowed value, the way a schema reads it: no positions, and nothing is allocated on the heap per value — strings without escapes point into text, lists and maps are in arena.

§Errors

SyntaxError when the text doesn’t parse.

let arena = substrate_data::Bump::new();
let v = substrate_data::text::parse_ref(r#"{ name: "docs", pages: [1, 2] }"#, &arena).unwrap();
assert_eq!(v.get("name").and_then(|n| n.as_str()), Some("docs"));