hcl/structure/
edit.rs

1use super::*;
2use crate::edit::structure;
3
4impl From<structure::Body> for Body {
5    fn from(value: structure::Body) -> Self {
6        Body::from_iter(value)
7    }
8}
9
10impl From<Body> for structure::Body {
11    fn from(value: Body) -> Self {
12        structure::Body::from_iter(value)
13    }
14}
15
16impl From<structure::Structure> for Structure {
17    fn from(value: structure::Structure) -> Self {
18        match value {
19            structure::Structure::Attribute(attr) => Structure::Attribute(attr.into()),
20            structure::Structure::Block(block) => Structure::Block(block.into()),
21        }
22    }
23}
24
25impl From<Structure> for structure::Structure {
26    fn from(value: Structure) -> Self {
27        match value {
28            Structure::Attribute(attr) => structure::Structure::Attribute(attr.into()),
29            Structure::Block(block) => structure::Structure::Block(block.into()),
30        }
31    }
32}
33
34impl From<structure::Attribute> for Attribute {
35    fn from(value: structure::Attribute) -> Self {
36        Attribute {
37            key: value.key.into(),
38            expr: value.value.into(),
39        }
40    }
41}
42
43impl From<Attribute> for structure::Attribute {
44    fn from(value: Attribute) -> Self {
45        structure::Attribute::new(value.key, value.expr)
46    }
47}
48
49impl From<structure::Block> for Block {
50    fn from(value: structure::Block) -> Self {
51        Block::builder(value.ident)
52            .add_labels(value.labels)
53            .add_structures(value.body)
54            .build()
55    }
56}
57
58impl From<Block> for structure::Block {
59    fn from(value: Block) -> Self {
60        structure::Block::builder(value.identifier)
61            .labels(value.labels)
62            .structures(value.body)
63            .build()
64    }
65}
66
67impl From<structure::BlockLabel> for BlockLabel {
68    fn from(value: structure::BlockLabel) -> Self {
69        match value {
70            structure::BlockLabel::Ident(ident) => BlockLabel::Identifier(ident.into()),
71            structure::BlockLabel::String(string) => BlockLabel::String(string.value_into()),
72        }
73    }
74}
75
76impl From<BlockLabel> for structure::BlockLabel {
77    fn from(value: BlockLabel) -> Self {
78        match value {
79            BlockLabel::Identifier(ident) => structure::BlockLabel::Ident(ident.into()),
80            BlockLabel::String(string) => structure::BlockLabel::String(string.into()),
81        }
82    }
83}