You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: lib.rs
    path of file: ./repos/tikv/components/tidb_query_aggr/src
    
    the code of the file until where you have to start completion: // Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

//! This crate provides aggregate functions for batch executors.

#![allow(incomplete_features)]
#![feature(proc_macro_hygiene)]
#![feature(specialization)]

#[macro_use(box_try)]
extern crate tikv_util;

#[macro_use(other_err)]
extern crate tidb_query_common;

mod impl_avg;
mod impl_bit_op;
mod impl_count;
mod impl_first;
mod impl_max_min;
mod impl_sum;
mod impl_variance;
mod parser;
mod summable;
mod util;

use tidb_query_common::Result;
use tidb_query_datatype::{codec::data_type::*, expr::EvalContext};

pub use self::parser::{AggrDefinitionParser, AllAggrDefinitionParser};

/// A trait for all single parameter aggregate functions.
///
/// Unlike ordinary function, aggregate function calculates a summary value over
/// multiple rows. To save memory, this functionality is provided via an
/// incremental update model:
///
/// - Each aggregate function associates a state structure, storing partially
/// computed aggregate results.
///
/// - The caller calls `update()` or `update_vector()` for each row to update
/// the state.
///
/// - The caller finally calls `push_result()` to aggregate a summary value and
/// push it into the given data container.
///
/// This trait can be auto derived by using `tidb_query_codegen::AggrFunction`.
pub trait AggrFunction: std::fmt::Debug + Send + 'static {
    /// The display name of the function.
    fn name(&self) -> &'static str;

    /// Creates a new state instance. Different states aggregate independently.
    fn create_state(&self) -> Box<dyn AggrFunctionState>;
}

/// A trait for all single parameter aggregate function states.
///
/// Aggregate function states are created by corresponding aggregate functions.
/// For each state, it can be updated or aggregated (to finalize a result)
/// independently.
///
/// Note that aggregate function states are strongly typed, that is, the caller
/// must provide the parameter in the correct data type for an aggregate
/// function states that calculates over this data type. To be safely boxed and
/// placed in a vector, interfaces are provided in a form that accept all kinds
/// of data type. However, unmatched types will result in panics in runtime.
pub trait AggrFunctionState:
    std::fmt::Debug
    + Send
    + 'static
    + AggrFunctionStateUpdatePartial<&'static Int>
    + AggrFunctionStateUpdatePartial<&'static Real>
    + AggrFunctionStateUpdatePartial<&'static Decimal>
    + AggrFunctionStateUpdatePartial<BytesRef<'static>>
    + AggrFunctionStateUpdatePartial<&'static DateTime>
    + AggrFunctionStateUpdatePartial<&'static Duration>
    + AggrFunctionStateUpdatePartial<JsonRef<'static>>
    + AggrFunctionStateUpdatePartial<EnumRef<'static>>
    + AggrFunctionStateUpdatePartial<SetRef<'static>>
{
    // TODO: A better implementation is to specialize different push result targets.
    // However current aggreg
    
    fn test_type_match() {
        /// A state that accepts Int and outputs Real.
        #[derive(Clone, Debug)]
        struct AggrFnStateFoo {
            sum: i64,
        }

        impl AggrFnStateFoo {
            fn new() -> Self {
                Self { sum: 0 }
            }
        }

        impl ConcreteAggrFunctionState for AggrFnStateFoo {
            type ParameterType = &'static Int;

            unsafe fn update_concrete_unsafe(
                &mut self,
                _ctx: &mut EvalContext,
                value: Option<&'static Int>,
            ) -> Result<()> {
                if let Some(v) = value {
                    self.sum += *v;
                }
                Ok(())
            }

            fn push_result(
                &self,
                _ctx: &mut EvalContext,
                target: &mut [VectorValue],
            ) -> Result<()> {
                target[0].push_real(Real::new(self.sum as f64).ok());
                Ok(())
            }
        }

        let mut ctx = EvalContext::default();
        let mut s = AggrFnStateFoo::new();

        // Update using `Int` should success.
        update!(
            &mut s as &mut dyn AggrFunctionStateUpdatePartial<_>,
            &mut ctx,
            Some(&1)
        )
        .unwrap();
        update!(
            &mut s as &mut dyn AggrFunctionStateUpdatePartial<_>,
            &mut ctx,
            Some(&3)
        )
        .unwrap();

        // Update using other data type should panic.
        let result = panic_hook::recover_safe(|| {
            let mut s = s.clone();
            let _ = update!(
                &mut s as &mut dyn AggrFunctionStateUpdatePartial<_>,
                &mut ctx,
                Real::new(1.0).ok().as_ref()
            );
        });
        result.unwrap_err();

        let result = panic_hook::recover_safe(|| {
            let mut s = s.clone();
            let _ = update!(
                &mut s as &mut dyn AggrFunctionStateUpdatePartial<_>,
                &mut ctx,
                Some(&[1u8] as BytesRef<'_>)
            );
        });
        result.unwrap_err();

        // Push result to Real VectorValue should success.
        let mut target = vec![VectorValue::with_capacity(0, EvalType::Real)];

        (&mut s as &mut dyn AggrFunctionState)
            .push_result(&mut ctx, &mut target)
            .unwrap();
        assert_eq!(target[0].to_real_vec(), &[Real::new(4.0).ok()]);

        // Calling push result multiple times should also success.
        update!(
            &mut s as &mut dyn AggrFunctionStateUpdatePartial<_>,
            &mut ctx,
            Some(&1)
        )
        .unwrap();
        (&mut s as &mut dyn AggrFunctionState)
            .push_result(&mut ctx, &mut target)
            .unwrap();
        assert_eq!(
            target[0].to_real_vec(),
            &[Real::new(4.0).ok(), Real::new(5.0).ok()]
        );

        // Push result into other VectorValue should panic.
        let result = panic_hook::recover_safe(|| {
            let mut s = s.clone();
            let mut target: Vec<VectorValue> = Vec::new();
            let _ = (&mut s as &mut dyn AggrFunctionState).push_result(&mut ctx, &mut target[..]);
        });
        result.unwrap_err();

        let result = panic_hook::recover_safe(|| {
            let mut s = s.clone();
            let mut target: Vec<VectorValue> = vec![VectorValue::with_capacity(0, EvalType::Int)];
            let _ = (&mut s as &mut dyn AggrFunctionState).push_result(&mut ctx, &mut target[..]);
        });
        result.unwrap_err();
    }