hcl/structure/
edit.rs

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
74
75
76
77
78
79
80
81
82
83
use super::*;
use crate::edit::structure;

impl From<structure::Body> for Body {
    fn from(value: structure::Body) -> Self {
        Body::from_iter(value)
    }
}

impl From<Body> for structure::Body {
    fn from(value: Body) -> Self {
        structure::Body::from_iter(value)
    }
}

impl From<structure::Structure> for Structure {
    fn from(value: structure::Structure) -> Self {
        match value {
            structure::Structure::Attribute(attr) => Structure::Attribute(attr.into()),
            structure::Structure::Block(block) => Structure::Block(block.into()),
        }
    }
}

impl From<Structure> for structure::Structure {
    fn from(value: Structure) -> Self {
        match value {
            Structure::Attribute(attr) => structure::Structure::Attribute(attr.into()),
            Structure::Block(block) => structure::Structure::Block(block.into()),
        }
    }
}

impl From<structure::Attribute> for Attribute {
    fn from(value: structure::Attribute) -> Self {
        Attribute {
            key: value.key.into(),
            expr: value.value.into(),
        }
    }
}

impl From<Attribute> for structure::Attribute {
    fn from(value: Attribute) -> Self {
        structure::Attribute::new(value.key, value.expr)
    }
}

impl From<structure::Block> for Block {
    fn from(value: structure::Block) -> Self {
        Block::builder(value.ident)
            .add_labels(value.labels)
            .add_structures(value.body)
            .build()
    }
}

impl From<Block> for structure::Block {
    fn from(value: Block) -> Self {
        structure::Block::builder(value.identifier)
            .labels(value.labels)
            .structures(value.body)
            .build()
    }
}

impl From<structure::BlockLabel> for BlockLabel {
    fn from(value: structure::BlockLabel) -> Self {
        match value {
            structure::BlockLabel::Ident(ident) => BlockLabel::Identifier(ident.into()),
            structure::BlockLabel::String(string) => BlockLabel::String(string.value_into()),
        }
    }
}

impl From<BlockLabel> for structure::BlockLabel {
    fn from(value: BlockLabel) -> Self {
        match value {
            BlockLabel::Identifier(ident) => structure::BlockLabel::Ident(ident.into()),
            BlockLabel::String(string) => structure::BlockLabel::String(string.into()),
        }
    }
}