///
/// This function allows to replace any of the types when generating a c function declaration
/// Type replacement depends highly on where the function is being use.
///
This function allows to replace any of the types when generating a c function declaration
Type replacement depends highly on where the function is being use.
This function allows to replace any of the types when generating a c function declaration Type replacement depends highly on where the function is being use .
pub fn gen_c_def_filter<F>(&self, replace_first: Option<Option<Cow<str>>>, filter: F) -> String
    where
        F: Fn(usize, &Variable) -> Option<Cow<str>>,
    {
        let mut output = String::with_capacity(256);
        let arg_count = self.function_args.len();
        let mut skip_first = false;
        // This allows us to change the first parameter and it also supports to not have any parameter at all
        replace_first
            .map(|arg| {
                skip_first = true;
                arg
            }).and_then(|v| v)
            .map(|v| {
                if arg_count > 0 {
                    output.push_str(&format!("{} {}", v, self.function_args[0].name));
                }
                if arg_count > 1 {
                    output.push_str(", ");
                }
            });
        // iterater over all the parameters and run the filter
        for (i, arg) in self.function_args.iter().enumerate() {
            if i == 0 && skip_first {
                continue;
            }
            let filter_arg = filter(i, &arg);
            let current_arg = filter_arg.map_or_else(|| arg.get_c_type(IsReturnType::No), |v| v);
            output.push_str(&format!("{} {}", current_arg, arg.name));
            if i != arg_count - 1 {
                output.push_str(", ");
            }
        }
        output
    }
pub fn gen_c_def_filter < F > ( & self , replace_first : Option < Option < Cow < str > > > , filter : F ) -> String where F : Fn ( usize , & Variable ) -> Option < Cow < str > > , { let mut output = String :: with_capacity ( 256 ) ; let arg_count = self . function_args . len ( ) ; let mut skip_first = false ; // This allows us to change the first parameter and it also supports to not have any parameter at all replace_first . map ( | arg | { skip_first = true ; arg } ) . and_then ( | v | v ) . map ( | v | { if arg_count > 0 { output . push_str ( & format ! ( " " v self function_args [ 0 ] name ) ) ; } if arg_count > 1 { output . push_str ( " " ) ; } } ) ; // iterater over all the parameters and run the filter for ( i , arg ) in self . function_args . iter ( ) . enumerate ( ) { if i == 0 && skip_first { continue ; } let filter_arg = filter ( i , & arg ) ; let current_arg = filter_arg . map_or_else ( | | arg . get_c_type ( IsReturnType :: No ) , | v | v ) ; output . push_str ( & format ! ( " " current_arg arg name ) ) ; if i != arg_count - 1 { output . push_str ( " " ) ; } } output }
This function allows to replace any of the types when generating a c function declaration
Type replacement depends highly on where the function is being use.
This function allows to replace any of the types when generating a c function declaration Type replacement depends highly on where the function is being use .
&self
replace_first
Option<Option<Cow<str>>>
filter
F