vrl/compiler/expression/
unary.rs1use std::fmt;
2
3use crate::compiler::{
4 Context, Expression,
5 expression::{Not, Resolved},
6 state::{TypeInfo, TypeState},
7};
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct Unary {
11 variant: Variant,
12}
13
14impl Unary {
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 Not(Not),
24}
25
26impl Expression for Unary {
27 fn resolve(&self, ctx: &mut Context) -> Resolved {
28 use Variant::Not;
29
30 match &self.variant {
31 Not(v) => v.resolve(ctx),
32 }
33 }
34
35 fn type_info(&self, state: &TypeState) -> TypeInfo {
36 use Variant::Not;
37
38 let mut state = state.clone();
39
40 let result = match &self.variant {
41 Not(v) => v.apply_type_info(&mut state),
42 };
43 TypeInfo::new(state, result)
44 }
45}
46
47impl fmt::Display for Unary {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 use Variant::Not;
50
51 match &self.variant {
52 Not(v) => v.fmt(f),
53 }
54 }
55}
56
57impl From<Not> for Variant {
58 fn from(not: Not) -> Self {
59 Variant::Not(not)
60 }
61}