yaml_subset/yaml/
hash_data.rs1use super::insert::Additive;
2use super::YamlInsert;
3use super::{AliasedYaml, HashElement, Yaml};
4use crate::yaml::{MapYaml, Pretty, VisitYaml};
5use crate::YamlPath;
6
7#[derive(Debug, Clone, PartialEq)]
8pub enum HashData {
9 InlineComment(String),
10 Comment(String),
11 Element(HashElement),
12}
13
14impl YamlInsert for HashData {
15 fn edit_hash_structure<F>(&mut self, path: &YamlPath, f: &F) -> usize
16 where
17 F: Fn(&mut Vec<HashData>, String, Option<usize>) -> usize,
18 {
19 match self {
20 HashData::Element(e) => e.edit_hash_structure(path, f),
21 _ => 0,
22 }
23 }
24 fn for_hash<F, R, A: Additive>(&mut self, path: &YamlPath, f: &F, r: &R) -> A
25 where
26 F: Fn(&mut HashElement) -> A,
27 R: Fn(&mut Yaml) -> A,
28 {
29 match self {
30 HashData::Element(e) => e.for_hash(path, f, r),
31 _ => A::zero(),
32 }
33 }
34}
35
36impl VisitYaml for HashData {
37 fn visit_yaml<F: FnMut(&AliasedYaml)>(&self, f: &mut F) {
38 if let HashData::Element(e) = self {
39 e.value.visit_yaml(f);
40 }
41 }
42}
43
44impl MapYaml for HashData {
45 fn map_yaml<F: FnMut(Yaml) -> Yaml>(self, f: &mut F) -> Self {
46 match self {
47 HashData::Element(e) => HashData::Element(e.map_yaml(f)),
48 other => other,
49 }
50 }
51}
52
53impl Pretty for HashData {
54 fn pretty_with_options(self, in_inline: bool, child_of_array: bool) -> Self {
55 match self {
56 HashData::Element(e) => HashData::Element(e.pretty_with_options(in_inline, child_of_array)),
57 o => o,
58 }
59 }
60}