toasty_core/stmt/
expr_stmt.rs

1use super::{Expr, Insert, Statement};
2
3/// A statement used as an expression.
4///
5/// Wraps a statement (such as a subquery) so it can be used in expression
6/// contexts.
7///
8/// # Examples
9///
10/// ```text
11/// (SELECT max(age) FROM users)   // subquery as expression
12/// ```
13#[derive(Debug, Clone, PartialEq)]
14pub struct ExprStmt {
15    /// The wrapped statement.
16    pub stmt: Box<Statement>,
17}
18
19impl Expr {
20    pub fn stmt(stmt: impl Into<Statement>) -> Self {
21        Self::Stmt(ExprStmt {
22            stmt: Box::new(stmt.into()),
23        })
24    }
25}
26
27impl From<ExprStmt> for Expr {
28    fn from(value: ExprStmt) -> Self {
29        Self::Stmt(value)
30    }
31}
32
33impl From<Statement> for ExprStmt {
34    fn from(value: Statement) -> Self {
35        Self { stmt: value.into() }
36    }
37}
38
39impl From<Insert> for ExprStmt {
40    fn from(value: Insert) -> Self {
41        Self {
42            stmt: Box::new(Statement::from(value)),
43        }
44    }
45}
46
47impl From<Insert> for Expr {
48    fn from(value: Insert) -> Self {
49        Self::Stmt(value.into())
50    }
51}