qail_core/ast/builders/
cast.rs1use crate::ast::Expr;
4
5pub fn cast(expr: impl Into<Expr>, target_type: &str) -> CastBuilder {
7 CastBuilder {
8 expr: expr.into(),
9 target_type: target_type.to_string(),
10 alias: None,
11 }
12}
13
14#[derive(Debug, Clone)]
16pub struct CastBuilder {
17 pub(crate) expr: Expr,
18 pub(crate) target_type: String,
19 pub(crate) alias: Option<String>,
20}
21
22impl CastBuilder {
23 pub fn alias(mut self, name: &str) -> Expr {
25 self.alias = Some(name.to_string());
26 self.build()
27 }
28
29 pub fn build(self) -> Expr {
31 Expr::Cast {
32 expr: Box::new(self.expr),
33 target_type: self.target_type,
34 alias: self.alias,
35 }
36 }
37}
38
39impl From<CastBuilder> for Expr {
40 fn from(builder: CastBuilder) -> Self {
41 builder.build()
42 }
43}