pulumi_wasm_rust/
input_or_output.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::{Output, PulumiContext};
use serde::de::DeserializeOwned;
use serde::Serialize;

/// Wrapper for either static value or [Output]
pub enum InputOrOutput<T> {
    StaticValue(T),
    Output(Output<T>),
}

impl<T: Serialize> InputOrOutput<T> {
    #[doc(hidden)]
    pub fn get_output(self, engine: &PulumiContext) -> Output<T> {
        match self {
            InputOrOutput::StaticValue(value) => Output::new(engine, &value),
            InputOrOutput::Output(output) => output,
        }
    }
}

impl<T> From<Output<T>> for InputOrOutput<T> {
    fn from(output: Output<T>) -> Self {
        InputOrOutput::Output(output)
    }
}

impl<T: Default + Serialize> Default for InputOrOutput<T> {
    fn default() -> Self {
        InputOrOutput::StaticValue(Default::default())
    }
}

impl<T: Serialize> From<T> for InputOrOutput<T> {
    fn from(value: T) -> InputOrOutput<T> {
        InputOrOutput::StaticValue(value)
    }
}

impl<T: Serialize> From<T> for InputOrOutput<Option<T>> {
    fn from(value: T) -> Self {
        InputOrOutput::StaticValue(Some(value))
    }
}

impl<T: Serialize + DeserializeOwned> From<Output<T>> for InputOrOutput<Option<T>> {
    fn from(output: Output<T>) -> Self {
        InputOrOutput::Output(output.map(|v| Some(v)))
    }
}

impl From<&str> for InputOrOutput<String> {
    fn from(value: &str) -> Self {
        InputOrOutput::StaticValue(value.to_string())
    }
}

impl From<&str> for InputOrOutput<Option<String>> {
    fn from(value: &str) -> Self {
        InputOrOutput::StaticValue(Some(value.to_string()))
    }
}

impl From<Vec<&str>> for InputOrOutput<Vec<String>> {
    fn from(value: Vec<&str>) -> Self {
        InputOrOutput::StaticValue(value.into_iter().map(|s| s.to_string()).collect())
    }
}

impl From<Vec<&str>> for InputOrOutput<Option<Vec<String>>> {
    fn from(value: Vec<&str>) -> Self {
        InputOrOutput::StaticValue(Some(value.into_iter().map(|s| s.to_string()).collect()))
    }
}

impl<T: Serialize, const N: usize> From<[T; N]> for InputOrOutput<Vec<T>>
where
    T: Serialize,
{
    fn from(value: [T; N]) -> Self {
        InputOrOutput::StaticValue(value.into_iter().collect())
    }
}

impl<T: Serialize, const N: usize> From<[T; N]> for InputOrOutput<Option<Vec<T>>>
where
    T: Serialize,
{
    fn from(value: [T; N]) -> Self {
        InputOrOutput::StaticValue(Some(value.into_iter().collect()))
    }
}

impl<const N: usize> From<[&str; N]> for InputOrOutput<Vec<String>> {
    fn from(value: [&str; N]) -> Self {
        InputOrOutput::StaticValue(value.into_iter().map(|s| s.to_string()).collect())
    }
}

impl<const N: usize> From<[&str; N]> for InputOrOutput<Option<Vec<String>>> {
    fn from(value: [&str; N]) -> Self {
        InputOrOutput::StaticValue(Some(value.into_iter().map(|s| s.to_string()).collect()))
    }
}