pub trait ScalarFunction: Send + Sync {
// Required methods
fn invoke(&self, args: &[SqliteValue]) -> Result<SqliteValue>;
fn num_args(&self) -> i32;
fn name(&self) -> &str;
// Provided methods
fn invoke_with_arg_subtypes(
&self,
args: &[SqliteValue],
_arg_subtypes: &[u32],
) -> Result<SqliteValue> { ... }
fn consumes_argument_collation(&self) -> bool { ... }
fn invoke_with_collation(
&self,
args: &[SqliteValue],
_collation: Option<&dyn CollationFunction>,
) -> Result<SqliteValue> { ... }
fn result_subtype(&self) -> Option<u32> { ... }
fn is_deterministic(&self) -> bool { ... }
fn min_args(&self) -> i32 { ... }
fn max_args(&self) -> Option<i32> { ... }
fn arity(&self) -> FunctionArity { ... }
}Required Methods§
Sourcefn invoke(&self, args: &[SqliteValue]) -> Result<SqliteValue>
fn invoke(&self, args: &[SqliteValue]) -> Result<SqliteValue>
Execute this function on the given arguments.
Provided Methods§
Sourcefn invoke_with_arg_subtypes(
&self,
args: &[SqliteValue],
_arg_subtypes: &[u32],
) -> Result<SqliteValue>
fn invoke_with_arg_subtypes( &self, args: &[SqliteValue], _arg_subtypes: &[u32], ) -> Result<SqliteValue>
Execute this function with knowledge of each argument’s value subtype
(e.g. JSON_SUBTYPE for values returned by JSON functions).
The default ignores subtypes and delegates to Self::invoke. JSON
constructors (json_object, json_array, the JSON mutators) override
this so a JSON-subtyped TEXT argument is embedded as a JSON value
instead of being quoted as a plain string — matching C SQLite, which
keys this behaviour off sqlite3_value_subtype().
Sourcefn consumes_argument_collation(&self) -> bool
fn consumes_argument_collation(&self) -> bool
Whether this function consumes the SQL collation selected from its
arguments (for example built-in nullif, scalar min, and scalar
max). Custom functions default to collation-opaque semantics.
Sourcefn invoke_with_collation(
&self,
args: &[SqliteValue],
_collation: Option<&dyn CollationFunction>,
) -> Result<SqliteValue>
fn invoke_with_collation( &self, args: &[SqliteValue], _collation: Option<&dyn CollationFunction>, ) -> Result<SqliteValue>
Invoke with the selected SQL collation, when this implementation
advertises Self::consumes_argument_collation.
The default deliberately ignores the collation so a custom function that happens to replace a collation-consuming built-in keeps its own semantics.
Sourcefn result_subtype(&self) -> Option<u32>
fn result_subtype(&self) -> Option<u32>
The subtype this function tags onto its result value, if any.
Returns JSON_SUBTYPE for functions whose result is JSON text so the
engine can propagate the tag to the destination register. Defaults to
None (no subtype).
Sourcefn is_deterministic(&self) -> bool
fn is_deterministic(&self) -> bool
Whether this function is deterministic (same inputs → same output).
Deterministic functions enable constant folding and other query
planner optimizations. Defaults to true.
Sourcefn min_args(&self) -> i32
fn min_args(&self) -> i32
Minimum accepted argument count for a variadic function.
The default is zero. Fixed-arity functions are matched directly from
Self::num_args and do not consult this method.
Sourcefn max_args(&self) -> Option<i32>
fn max_args(&self) -> Option<i32>
Maximum accepted argument count for a variadic function.
The default is unbounded. Fixed-arity functions are matched directly
from Self::num_args and do not consult this method.
Sourcefn arity(&self) -> FunctionArity
fn arity(&self) -> FunctionArity
Return the complete SQL-visible arity contract in one metadata call.
Registries use this method exactly once before publishing a function,
so a reentrant or stateful Self::num_args implementation cannot
produce a key and bounds from different observations. Implementations
with dynamically-computed metadata may override this method directly.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".