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
use super::{Expression, Value};
use serde::{Deserialize, Serialize};
use std::iter;
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
#[serde(rename = "$hcl::attribute")]
pub struct Attribute {
    
    pub key: String,
    
    pub expr: Expression,
}
impl Attribute {
    
    
    pub fn new<K, V>(key: K, expr: V) -> Attribute
    where
        K: Into<String>,
        V: Into<Expression>,
    {
        Attribute {
            key: key.into(),
            expr: expr.into(),
        }
    }
    
    pub fn key(&self) -> &str {
        &self.key
    }
    
    pub fn expr(&self) -> &Expression {
        &self.expr
    }
}
impl From<Attribute> for Value {
    fn from(attr: Attribute) -> Value {
        Value::from_iter(iter::once((attr.key, attr.expr)))
    }
}
impl<K, V> From<(K, V)> for Attribute
where
    K: Into<String>,
    V: Into<Expression>,
{
    fn from(pair: (K, V)) -> Attribute {
        Attribute::new(pair.0.into(), pair.1.into())
    }
}