fluidattacks-blends-domain 0.28.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::adj_ast;
use crate::syntax::builders::pair::build_pair_node;
use crate::syntax::fields::go::keyed_element;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    // Both sides come wrapped in a `literal_element`, which builds no node of
    // its own, so the pair points at what the wrapper holds.
    let graph = args.ast_graph;
    let key_id = args.required_field_alt(n_id, keyed_element::KEY)?;
    let value_id = args.required_field_alt(n_id, keyed_element::VALUE)?;
    let key_child = adj_ast(graph, key_id, None, &[])
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
    let value_child = adj_ast(graph, value_id, None, &[])
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
    build_pair_node(args, n_id, key_child, value_child).map(Some)
}