Function dynparser::ast::consume_val
source · Expand description
Given a slice of nodes, return the value (&str) of first node if it is a Node::Rule and return the rest of nodes
If it’s not possible, return an error
use dynparser::ast;
let nodes = vec![
ast::Node::Val("hello".to_string()),
ast::Node::Val("world".to_string()),
];
let (val, nodes) = ast::consume_val(&nodes).unwrap();
assert!(val == "hello");
assert!(nodes.len() == 1);
let (val, nodes) = ast::consume_val(&nodes).unwrap();
assert!(val == "world");
assert!(nodes.len() == 0);