Skip to main content

parse

Function parse 

Source
pub fn parse(
    filename: &str,
    yaml: &str,
    dynamic: &mut DynamicPool,
    path_map: &mut PathMap,
    children_map: &mut ChildrenMap,
    keys: &mut KeyList,
    values: &mut YamlValueList,
) -> Result<ParsedManifest, String>
Expand description

Parses a YAML manifest string, appending into shared pool structures. Returns a ParsedManifest referencing the file root record’s index.

§Examples

use state_engine::common::parser::parse;
use state_engine::common::pool::{DynamicPool, PathMap, ChildrenMap, KeyList, YamlValueList};
use state_engine::common::bit;

let yaml = "
user:
  _store:
    client: KVS
    key: 'user:${session.sso_user_id}'
    ttl: 14400
  id:
    _state:
      type: integer
";

let mut dynamic = DynamicPool::new();
let mut path_map = PathMap::new();
let mut children_map = ChildrenMap::new();
let mut keys = KeyList::new();
let mut values = YamlValueList::new();

let pm = parse("cache", yaml, &mut dynamic, &mut path_map, &mut children_map, &mut keys, &mut values).unwrap();

// file root record is at pm.file_key_idx
let root = keys.get(pm.file_key_idx).unwrap();
let dyn_idx = bit::get(root, bit::OFFSET_DYNAMIC, bit::MASK_DYNAMIC) as u16;
assert_eq!(dynamic.get(dyn_idx), Some("cache"));