vrl/compiler/expression/
container.rs1use std::fmt;
2
3use crate::compiler::{
4 Context, Expression,
5 expression::{Array, Block, Group, Object, Resolved, Value},
6 state::{TypeInfo, TypeState},
7};
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct Container {
11 pub variant: Variant,
12}
13
14impl Container {
15 #[must_use]
16 pub fn new(variant: Variant) -> Self {
17 Self { variant }
18 }
19}
20
21#[derive(Debug, Clone, PartialEq)]
22pub enum Variant {
23 Group(Group),
24 Block(Block),
25 Array(Array),
26 Object(Object),
27}
28
29impl Expression for Container {
30 fn resolve(&self, ctx: &mut Context) -> Resolved {
31 use Variant::{Array, Block, Group, Object};
32
33 match &self.variant {
34 Group(v) => v.resolve(ctx),
35 Block(v) => v.resolve(ctx),
36 Array(v) => v.resolve(ctx),
37 Object(v) => v.resolve(ctx),
38 }
39 }
40
41 fn resolve_constant(&self, state: &TypeState) -> Option<Value> {
42 use Variant::{Array, Block, Group, Object};
43
44 match &self.variant {
45 Group(v) => v.resolve_constant(state),
46 Block(v) => v.resolve_constant(state),
47 Array(v) => v.resolve_constant(state),
48 Object(v) => v.resolve_constant(state),
49 }
50 }
51
52 fn type_info(&self, state: &TypeState) -> TypeInfo {
53 use Variant::{Array, Block, Group, Object};
54
55 match &self.variant {
56 Group(v) => v.type_info(state),
57 Block(v) => v.type_info(state),
58 Array(v) => v.type_info(state),
59 Object(v) => v.type_info(state),
60 }
61 }
62}
63
64impl fmt::Display for Container {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 use Variant::{Array, Block, Group, Object};
67
68 match &self.variant {
69 Group(v) => v.fmt(f),
70 Block(v) => v.fmt(f),
71 Array(v) => v.fmt(f),
72 Object(v) => v.fmt(f),
73 }
74 }
75}
76
77impl From<Group> for Variant {
78 fn from(group: Group) -> Self {
79 Variant::Group(group)
80 }
81}
82
83impl From<Block> for Variant {
84 fn from(block: Block) -> Self {
85 Variant::Block(block)
86 }
87}
88
89impl From<Array> for Variant {
90 fn from(array: Array) -> Self {
91 Variant::Array(array)
92 }
93}
94
95impl From<Object> for Variant {
96 fn from(object: Object) -> Self {
97 Variant::Object(object)
98 }
99}