fn unique_criterias(&self, allow_optional: bool, disregard_unsupported: bool) -> Vec<UniqueCriteria> {
        let mut result = Vec::new();

        let in_eligible = |field: &ScalarField| {
            if disregard_unsupported {
                field.is_commented_out || matches!(field.field_type, FieldType::Unsupported(_))
            } else {
                field.is_commented_out
            }
        };

        // first candidate: the singular id field
        {
            if let Some(x) = self.singular_id_fields().next() {
                if !in_eligible(x) {
                    result.push(UniqueCriteria::new(vec![x]))
                }
            }
        }

        // second candidate: the multi field id
        {
            let id_fields: Vec<_> = self
                .id_fields
                .iter()
                .map(|f| self.find_scalar_field(&f).unwrap())
                .collect();

            if !id_fields.is_empty() && !id_fields.iter().any(|f| in_eligible(f)) {
                result.push(UniqueCriteria::new(id_fields));
            }
        }

        // third candidate: a required scalar field with a unique index.
        {
            let mut unique_required_fields: Vec<_> = self
                .scalar_fields()
                .filter(|field| field.is_unique && (field.is_required() || allow_optional) && !in_eligible(field))
                .map(|f| UniqueCriteria::new(vec![f]))
                .collect();

            result.append(&mut unique_required_fields);
        }

        // fourth candidate: any multi-field unique constraint where all fields are required
        {
            let mut unique_field_combi = self
                .indices
                .iter()
                .filter(|id| id.tpe == IndexType::Unique)
                .filter_map(|id| {
                    let fields: Vec<_> = id.fields.iter().map(|f| self.find_scalar_field(&f).unwrap()).collect();
                    let no_fields_are_commented_out = !fields.iter().any(|f| in_eligible(f));
                    let all_fields_are_required = fields.iter().all(|f| f.is_required());
                    if (all_fields_are_required || allow_optional) && no_fields_are_commented_out {
                        Some(UniqueCriteria::new(fields))
                    } else {
                        None
                    }
                })
                .collect();

            result.append(&mut unique_field_combi)
        }

        result
    }
/// returns the order of unique criterias ordered based on their precedence
returns the order of unique criterias ordered based on their precedence
returns the order of unique criterias ordered based on their precedence
fn unique_criterias(&self, allow_optional: bool, disregard_unsupported: bool) -> Vec<UniqueCriteria> {
        let mut result = Vec::new();
        let in_eligible = |field: &ScalarField| {
            if disregard_unsupported {
                field.is_commented_out || matches!(field.field_type, FieldType::Unsupported(_))
            } else {
                field.is_commented_out
            }
        };
        // first candidate: the singular id field
        {
            if let Some(x) = self.singular_id_fields().next() {
                if !in_eligible(x) {
                    result.push(UniqueCriteria::new(vec![x]))
                }
            }
        }
        // second candidate: the multi field id
        {
            let id_fields: Vec<_> = self
                .id_fields
                .iter()
                .map(|f| self.find_scalar_field(&f).unwrap())
                .collect();
            if !id_fields.is_empty() && !id_fields.iter().any(|f| in_eligible(f)) {
                result.push(UniqueCriteria::new(id_fields));
            }
        }
        // third candidate: a required scalar field with a unique index.
        {
            let mut unique_required_fields: Vec<_> = self
                .scalar_fields()
                .filter(|field| field.is_unique && (field.is_required() || allow_optional) && !in_eligible(field))
                .map(|f| UniqueCriteria::new(vec![f]))
                .collect();
            result.append(&mut unique_required_fields);
        }
        // fourth candidate: any multi-field unique constraint where all fields are required
        {
            let mut unique_field_combi = self
                .indices
                .iter()
                .filter(|id| id.tpe == IndexType::Unique)
                .filter_map(|id| {
                    let fields: Vec<_> = id.fields.iter().map(|f| self.find_scalar_field(&f).unwrap()).collect();
                    let no_fields_are_commented_out = !fields.iter().any(|f| in_eligible(f));
                    let all_fields_are_required = fields.iter().all(|f| f.is_required());
                    if (all_fields_are_required || allow_optional) && no_fields_are_commented_out {
                        Some(UniqueCriteria::new(fields))
                    } else {
                        None
                    }
                })
                .collect();
            result.append(&mut unique_field_combi)
        }
        result
    }
fn unique_criterias ( & self , allow_optional : bool , disregard_unsupported : bool ) -> Vec < UniqueCriteria > { let mut result = Vec :: new ( ) ; let in_eligible = | field : & ScalarField | { if disregard_unsupported { field . is_commented_out || matches ! ( field field_type FieldType Unsupported ( ) ) } else { field . is_commented_out } } ; // first candidate: the singular id field { if let Some ( x ) = self . singular_id_fields ( ) . next ( ) { if ! in_eligible ( x ) { result . push ( UniqueCriteria :: new ( vec ! [ x ] ) ) } } } // second candidate: the multi field id { let id_fields : Vec < _ > = self . id_fields . iter ( ) . map ( | f | self . find_scalar_field ( & f ) . unwrap ( ) ) . collect ( ) ; if ! id_fields . is_empty ( ) && ! id_fields . iter ( ) . any ( | f | in_eligible ( f ) ) { result . push ( UniqueCriteria :: new ( id_fields ) ) ; } } // third candidate: a required scalar field with a unique index. { let mut unique_required_fields : Vec < _ > = self . scalar_fields ( ) . filter ( | field | field . is_unique && ( field . is_required ( ) || allow_optional ) && ! in_eligible ( field ) ) . map ( | f | UniqueCriteria :: new ( vec ! [ f ] ) ) . collect ( ) ; result . append ( & mut unique_required_fields ) ; } // fourth candidate: any multi-field unique constraint where all fields are required { let mut unique_field_combi = self . indices . iter ( ) . filter ( | id | id . tpe == IndexType :: Unique ) . filter_map ( | id | { let fields : Vec < _ > = id . fields . iter ( ) . map ( | f | self . find_scalar_field ( & f ) . unwrap ( ) ) . collect ( ) ; let no_fields_are_commented_out = ! fields . iter ( ) . any ( | f | in_eligible ( f ) ) ; let all_fields_are_required = fields . iter ( ) . all ( | f | f . is_required ( ) ) ; if ( all_fields_are_required || allow_optional ) && no_fields_are_commented_out { Some ( UniqueCriteria :: new ( fields ) ) } else { None } } ) . collect ( ) ; result . append ( & mut unique_field_combi ) } result }
returns the order of unique criterias ordered based on their precedence
returns the order of unique criterias ordered based on their precedence
&self
allow_optional
bool
disregard_unsupported
bool
&self
allow_optional
bool
disregard_unsupported
bool