Skip to main content

surrealdb_expr/expr/convert/
function.rs

1//! `sql` -> `expr` conversions for [`crate::sql::function`].
2//!
3//! Lives in core rather than beside the AST: `surrealdb-sql` sits below
4//! core, so it cannot name `expr` types.
5
6use crate::sql::function::*;
7
8impl From<Function> for crate::expr::Function {
9	fn from(v: Function) -> Self {
10		match v {
11			Function::Normal(s) => crate::expr::Function::Normal(s),
12			Function::Custom(s) => crate::expr::Function::Custom(s),
13			Function::Script(s) => crate::expr::Function::Script(s.into()),
14			Function::Model(m) => crate::expr::Function::Model(m.into()),
15			Function::Module(m, s) => crate::expr::Function::Module(m, s),
16			Function::Silo {
17				org,
18				pkg,
19				major,
20				minor,
21				patch,
22				sub,
23			} => crate::expr::Function::Silo {
24				org,
25				pkg,
26				major,
27				minor,
28				patch,
29				sub,
30			},
31		}
32	}
33}
34
35impl From<crate::expr::Function> for Function {
36	fn from(v: crate::expr::Function) -> Self {
37		match v {
38			crate::expr::Function::Normal(s) => Self::Normal(s),
39			crate::expr::Function::Custom(s) => Self::Custom(s),
40			crate::expr::Function::Script(s) => Self::Script(s.into()),
41			crate::expr::Function::Model(m) => Self::Model(m.into()),
42			crate::expr::Function::Module(m, s) => Self::Module(m, s),
43			crate::expr::Function::Silo {
44				org,
45				pkg,
46				major,
47				minor,
48				patch,
49				sub,
50			} => Self::Silo {
51				org,
52				pkg,
53				major,
54				minor,
55				patch,
56				sub,
57			},
58		}
59	}
60}
61
62impl From<FunctionCall> for crate::expr::FunctionCall {
63	fn from(value: FunctionCall) -> Self {
64		crate::expr::FunctionCall {
65			receiver: value.receiver.into(),
66			arguments: value.arguments.into_iter().map(Into::into).collect(),
67		}
68	}
69}
70
71impl From<crate::expr::FunctionCall> for FunctionCall {
72	fn from(value: crate::expr::FunctionCall) -> Self {
73		FunctionCall {
74			receiver: value.receiver.into(),
75			arguments: value.arguments.into_iter().map(Into::into).collect(),
76		}
77	}
78}