Skip to main content

AggregateFunction

Trait AggregateFunction 

Source
pub trait AggregateFunction<UserData>: FromUserData<UserData> {
    // Required methods
    fn step(
        &mut self,
        context: &Context,
        args: &mut [&mut ValueRef],
    ) -> Result<()>;
    fn value(&self, context: &Context) -> Result<()>;
    fn inverse(
        &mut self,
        context: &Context,
        args: &mut [&mut ValueRef],
    ) -> Result<()>;

    // Provided method
    fn default_value(user_data: &UserData, context: &Context) -> Result<()>
       where Self: Sized { ... }
}
Expand description

Implement an application-defined aggregate window function.

The function can be registered with a database connection using Connection::create_aggregate_function.

Required Methods§

Source

fn step(&mut self, context: &Context, args: &mut [&mut ValueRef]) -> Result<()>

Add a new row to the aggregate.

Source

fn value(&self, context: &Context) -> Result<()>

Assign the current value of the aggregate function to the context using Context::set_result. If no result is set, SQL NULL is returned. If the function returns an Err value, the SQL statement will fail, even if a result had been set before the failure.

Source

fn inverse( &mut self, context: &Context, args: &mut [&mut ValueRef], ) -> Result<()>

Remove the oldest presently aggregated row.

The args are the same that were passed to AggregateFunction::step when this row was added.

Provided Methods§

Source

fn default_value(user_data: &UserData, context: &Context) -> Result<()>
where Self: Sized,

Assign the default value of the aggregate function to the context using Context::set_result.

This method is called when the aggregate function is invoked over an empty set of rows. The default implementation is equivalent to Self::from_user_data(user_data).value(context).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§