11//! Dispatch machinery for the built-in `sqlpage.*` SQL functions.
22//!
33//! Each function is a plain `async fn` in its own module under [`functions/`](super::functions).
4- //! `build.rs` lists those modules and the [`sqlpage_functions!`] macro turns the list into the
5- //! [`SqlPageFunctionName`](super::functions::SqlPageFunctionName) enum the engine dispatches on, so
6- //! functions register themselves just by existing. Adapting each signature to the uniform
4+ //! [`sqlpage_functions!`] turns the module list in [`functions`](super::functions) into the
5+ //! [`SqlPageFunctionName`](super::functions::SqlPageFunctionName) enum the engine dispatches on.
6+ //! Adapting each signature to the uniform
77//! `(request, db, args) -> Option<string>` convention is done generically by [`Extract`] (per
88//! argument type), [`Handler`] (per argument count, the trick `axum` uses) and [`IntoCowResult`]
99//! (per return type); the macro itself carries no type-level glue.
@@ -217,17 +217,11 @@ impl<'a, T: IntoCow<'a>> IntoCow<'a> for Option<T> {
217217}
218218
219219/// Declares the listed function modules and builds the [`SqlPageFunctionName`] dispatch enum from
220- /// them. The list is produced by `build.rs`, so there is no hand-maintained registry.
220+ /// them.
221221macro_rules! sqlpage_functions {
222- ( $( $func: ident = $path : literal ) ,* $( , ) ?) => {
222+ ( $( $func: ident) ,* $( , ) ?) => {
223223 $(
224- // `build.rs` passes the absolute path because the `mod` is expanded from a file
225- // `include!`d out of `OUT_DIR`, where the default relative lookup would not find it.
226- #[ path = $path]
227224 mod $func;
228- // Re-export so sibling modules can use each other's helpers via `use super::*`.
229- #[ allow( unused_imports) ]
230- use $func:: * ;
231225 ) *
232226
233227 /// One variant per built-in `sqlpage.*` function.
@@ -238,12 +232,20 @@ macro_rules! sqlpage_functions {
238232 }
239233
240234 impl SqlPageFunctionName {
235+ const ALL : & ' static [ Self ] = & [ $( Self :: $func) ,* ] ;
236+
237+ fn name( self ) -> & ' static str {
238+ match self {
239+ $( Self :: $func => stringify!( $func) ) ,*
240+ }
241+ }
242+
241243 pub ( crate ) async fn evaluate<' a, ' c>(
242244 self ,
243- request: & ' a ExecutionContext ,
244- db_connection: & ' c mut DbConn ,
245- arguments: Vec <Option <Cow <' a, str >>>,
246- ) -> anyhow:: Result <Option <Cow <' a, str >>>
245+ request: & ' a $crate :: webserver :: http_request_info :: ExecutionContext ,
246+ db_connection: & ' c mut $crate :: webserver :: database :: execute_queries :: DbConn ,
247+ arguments: Vec <Option <:: std :: borrow :: Cow <' a, str >>>,
248+ ) -> anyhow:: Result <Option <:: std :: borrow :: Cow <' a, str >>>
247249 where
248250 ' a: ' c,
249251 {
@@ -256,32 +258,6 @@ macro_rules! sqlpage_functions {
256258 }
257259 }
258260 }
259-
260- impl :: std:: str :: FromStr for SqlPageFunctionName {
261- type Err = anyhow:: Error ;
262-
263- fn from_str( name: & str ) -> anyhow:: Result <Self > {
264- match name {
265- $( stringify!( $func) => Ok ( SqlPageFunctionName :: $func) , ) *
266- unknown => anyhow:: bail!(
267- "Unknown function {unknown:?}. Supported functions:\n {}" ,
268- [ $( SqlPageFunctionName :: $func) ,* ]
269- . iter( )
270- . map( |f| format!( " - {f}\n " ) )
271- . collect:: <String >( )
272- ) ,
273- }
274- }
275- }
276-
277- impl :: std:: fmt:: Display for SqlPageFunctionName {
278- fn fmt( & self , f: & mut :: std:: fmt:: Formatter <' _>) -> :: std:: fmt:: Result {
279- f. write_str( "sqlpage." ) ?;
280- f. write_str( match self {
281- $( SqlPageFunctionName :: $func => stringify!( $func) ) ,*
282- } )
283- }
284- }
285261 } ;
286262}
287263
0 commit comments