/// Generate sorting functions
/// For all fields that decorated by `cmp`, we will automatically generate a cmp_by_FIELD_NAME function. And for
/// All fields that decorated by `sort_tag`, we will use the associate cmp_by_FIELD_NAME function and generate a sort
/// function. The generated code will be something like this:
/// ```ignore
/// fn sort(&self, tag: TagType, children: Vec<ModelType>, reverse: bool) {
///     match tag {
///         TagType::Tag1 => children.sort_by(|lhs, rhs| {
///             if reverse {
///                 self.cmp_by_FIELD_NAME1(&lhs, &rhs)
///                     .unwrap_or(std::cmp::Ordering::Equal)
///                     .reverse()
///             } else {
///                 self.#cmp_by_FIELD_NAME1(&lhs, &rhs)
///                     .unwrap_or(std::cmp::Ordering::Equal)
///             }
///         }),
///         ...
///         _ => ()
///     }
/// }
/// ```
/// All fields without a sorting tagged will automatically tagged by TagType::Keep. So when defining sorting tag,
/// it's mandatory to have a field named Keep. Please note that all fields that are decorated by `sort_tag` will be automatically
/// set `cmp = true`
Generate sorting functions
For all fields that decorated by `cmp`, we will automatically generate a cmp_by_FIELD_NAME function. And for
All fields that decorated by `sort_tag`, we will use the associate cmp_by_FIELD_NAME function and generate a sort
function.
Generate sorting functions For all fields that decorated by ` cmp ` we will automatically generate a cmp_by_FIELD_NAME function . And for All fields that decorated by ` sort_tag ` we will use the associate cmp_by_FIELD_NAME function and generate a sort function .
pub fn generate_sort_fn(&self) -> Tstream {
        // No sort tag
        if self.sort_tag_type.is_none() {
            return quote! {};
        }
        let model_type = self.blink_type.clone().unwrap_or(quote! {Self});
        let sort_tag_type = self.sort_tag_type.as_ref().unwrap();
        let match_arms = self
            .fields
            .iter()
            .filter(|f| f.sort_tag_type.is_some())
            .map(|f| {
                let cmp_fn_name = format!("cmp_by_{}", f.name).parse::<Tstream>().unwrap();
                let sort_tag_val = f.sort_tag_val.as_ref().unwrap();
                quote! {
                    #sort_tag_val => children.sort_by(|lhs, rhs| {
                        if reverse {
                            self.#cmp_fn_name(&lhs, &rhs)
                                .unwrap_or(std::cmp::Ordering::Equal)
                                .reverse()
                        } else {
                            self.#cmp_fn_name(&lhs, &rhs)
                                .unwrap_or(std::cmp::Ordering::Equal)
                        }
                    })
                }
            });
        quote! {
            pub fn sort(&self, tag: #sort_tag_type, children: &mut Vec<&#model_type>, reverse: bool) {
                match tag {
                    #(#match_arms,)*
                    _ => (),
                };
            }
        }
    }
pub fn generate_sort_fn ( & self ) -> Tstream { // No sort tag if self . sort_tag_type . is_none ( ) { return quote ! { } ; } let model_type = self . blink_type . clone ( ) . unwrap_or ( quote ! { Self } ) ; let sort_tag_type = self . sort_tag_type . as_ref ( ) . unwrap ( ) ; let match_arms = self . fields . iter ( ) . filter ( | f | f . sort_tag_type . is_some ( ) ) . map ( | f | { let cmp_fn_name = format ! ( " " f name ) . parse :: < Tstream > ( ) . unwrap ( ) ; let sort_tag_val = f . sort_tag_val . as_ref ( ) . unwrap ( ) ; quote ! { sort_tag_val children sort_by ( lhs rhs { if reverse { self cmp_fn_name ( lhs rhs ) unwrap_or ( std cmp Ordering Equal ) reverse ( ) } else { self cmp_fn_name ( lhs rhs ) unwrap_or ( std cmp Ordering Equal ) } } ) } } ) ; quote ! { pub fn sort ( self tag sort_tag_type children mut Vec model_type reverse bool ) { match tag { ( match_arms ) ( ) } } } }
Generate sorting functions
For all fields that decorated by `cmp`, we will automatically generate a cmp_by_FIELD_NAME function.
Generate sorting functions For all fields that decorated by ` cmp ` we will automatically generate a cmp_by_FIELD_NAME function .
&self