1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! YAML node type definitions.
//!
//! This module provides the core type enums shared across the API.
use fyaml_sys::*;
/// The type of a YAML node.
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum NodeType {
/// A scalar value (string, number, boolean, null).
Scalar,
/// A sequence (list/array) of nodes.
Sequence,
/// A mapping (dictionary/object) of key-value pairs.
Mapping,
}
/// The style of a YAML node (how it was/should be represented).
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum NodeStyle {
/// No specific style hint, let the emitter decide.
Any,
/// Flow style (inline) for sequences/mappings.
Flow,
/// Block style (indented) for sequences/mappings.
Block,
/// Plain scalar (no quotes).
Plain,
/// Single-quoted scalar.
SingleQuoted,
/// Double-quoted scalar.
DoubleQuoted,
/// Literal block scalar (|).
Literal,
/// Folded block scalar (>).
Folded,
/// Alias reference.
Alias,
}
impl From<i32> for NodeStyle {
fn from(value: i32) -> Self {
match value {
x if x == FYNS_ANY => NodeStyle::Any,
x if x == FYNS_FLOW => NodeStyle::Flow,
x if x == FYNS_BLOCK => NodeStyle::Block,
x if x == FYNS_PLAIN => NodeStyle::Plain,
x if x == FYNS_SINGLE_QUOTED => NodeStyle::SingleQuoted,
x if x == FYNS_DOUBLE_QUOTED => NodeStyle::DoubleQuoted,
x if x == FYNS_LITERAL => NodeStyle::Literal,
x if x == FYNS_FOLDED => NodeStyle::Folded,
x if x == FYNS_ALIAS => NodeStyle::Alias,
_ => NodeStyle::Any,
}
}
}
impl From<u32> for NodeType {
fn from(value: u32) -> Self {
match value {
x if x == FYNT_SCALAR => NodeType::Scalar,
x if x == FYNT_SEQUENCE => NodeType::Sequence,
x if x == FYNT_MAPPING => NodeType::Mapping,
_ => {
log::warn!(
"Unknown fy_node_type value: {}, defaulting to Scalar",
value
);
NodeType::Scalar
}
}
}
}