Skip to main content

parse_arti_path

Function parse_arti_path 

Source
pub fn parse_arti_path(
    arti_path: &ArtiPath,
    keys: &&[&str],
    path_parsers: &mut [&'_ mut dyn RawKeySpecifierComponentParser],
    leaf_parsers: &mut [&'_ mut dyn RawKeySpecifierComponentParser],
) -> Result<(), ArtiPathError>
Expand description

Parse a KeyPath as an ArtiPath like pc/pc/pc/lc_lc_lc

keys is the field names for each of the path_parsers and leaf_parsers, but only the ones which will return RCPR::ParsedField (or ::Invalid).

As with arti_path_string_components etc., we try to minimise the amount of macro-generated machine code.

The macro-generated impl again assembles two vectors, one for the path components and one for the leaf components.

For a field, the vector entry is a pointer to &mut Option<...> for the field, along with a RawKeySpecifierComponentParser vtable entry. (The macro-generated impl must unwrap each of these Options, to assemble the final struct. In principle this could be avoided with use of MaybeUninit and unsafe.)

For a fixed string component, the vector entry data pointer points to its &str. “Parsing” consists of checking that the string is as expected.

We also need the key names for error reporting. We pass this as a single array, and a double-reference to the slice, since that resolves to one pointer to a static structure.