pub enum Expr {
Aggregate(AggregateExpr),
Unary(UnaryExpr),
Binary(BinaryExpr),
Paren(ParenExpr),
Subquery(SubqueryExpr),
NumberLiteral(NumberLiteral),
StringLiteral(StringLiteral),
VectorSelector(VectorSelector),
MatrixSelector(MatrixSelector),
Call(Call),
Extension(Extension),
}
Variants§
Aggregate(AggregateExpr)
Aggregate represents an aggregation operation on a Vector.
Unary(UnaryExpr)
Unary represents a unary operation on another expression. Currently unary operations are only supported for Scalars.
Binary(BinaryExpr)
Binary represents a binary expression between two child expressions.
Paren(ParenExpr)
Paren wraps an expression so it cannot be disassembled as a consequence of operator precedence.
Subquery(SubqueryExpr)
SubqueryExpr represents a subquery.
NumberLiteral(NumberLiteral)
NumberLiteral represents a number.
StringLiteral(StringLiteral)
StringLiteral represents a string.
VectorSelector(VectorSelector)
VectorSelector represents a Vector selection.
MatrixSelector(MatrixSelector)
MatrixSelector represents a Matrix selection.
Call(Call)
Call represents a function call.
Extension(Extension)
Extension represents an extension expression. It is for user to attach additional information to the AST. This parser won’t generate Extension node.
Implementations§
Source§impl Expr
impl Expr
pub fn value_type(&self) -> ValueType
Sourcepub fn prettify(&self) -> String
pub fn prettify(&self) -> String
Examples found in repository?
17fn main() {
18 let promql = r#"
19 http_requests_total{
20 environment=~"staging|testing|development",
21 method!="GET"
22 } offset 5m
23 "#;
24
25 match parser::parse(promql) {
26 Ok(expr) => {
27 println!("Prettify:\n{}\n", expr.prettify());
28 println!("AST:\n{expr:?}");
29 }
30 Err(info) => println!("Err: {info:?}"),
31 }
32}
Trait Implementations§
Source§impl From<VectorSelector> for Expr
directly create an Expr::VectorSelector from instant vector
impl From<VectorSelector> for Expr
directly create an Expr::VectorSelector from instant vector
§Examples
Basic usage:
use promql_parser::label::Matchers;
use promql_parser::parser::{Expr, VectorSelector};
let name = String::from("foo");
let vs = VectorSelector::new(Some(name), Matchers::empty());
assert_eq!(Expr::VectorSelector(vs), Expr::from(VectorSelector::from("foo")));
Source§fn from(vs: VectorSelector) -> Self
fn from(vs: VectorSelector) -> Self
Source§impl Prettier for Expr
impl Prettier for Expr
Source§fn pretty(&self, level: usize, max: usize) -> String
fn pretty(&self, level: usize, max: usize) -> String
Source§fn format(&self, level: usize, _max: usize) -> String
fn format(&self, level: usize, _max: usize) -> String
Source§fn needs_split(&self, max: usize) -> bool
fn needs_split(&self, max: usize) -> bool
Source§impl TryFrom<Expr> for AtModifier
impl TryFrom<Expr> for AtModifier
impl Eq for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl !RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl !UnwindSafe for Expr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.