fn validate(&self) -> Result<(), Error> {
        // Ensure state numbers are monotonically increasing starting at 1
        {
            let state_numbers: Vec<_> = self.0.iter().map(|s| s.state).collect();
            let expected_state_numbers: Vec<_> = (1..self.0.len() as u32 + 1).collect();
            ensure!(
                state_numbers == expected_state_numbers,
                "State numbers must increase monotonically starting at 1 \
                (got invalid state numbers: {:?})",
                state_numbers
            );
        }

        // Ensure:
        //  1) trip points are well-formed (`deactivate_below` <= `activate_at`)
        //  2) for a given sensor, the [`deactivate_below`..=`activate_at`] range is strictly
        //     increasing and non-overlapping for successive trip points
        //  3) the same sensor is not referenced by multiple trip points in the same thermal state
        {
            // This map will be used to keep track of the highest encountered `activate_at` value
            // for each sensor as we iterate through the trip points. This will let us detect if any
            // trip points are overlapping or not increasing.
            let mut highest_activate_value: HashMap<String, u32> = HashMap::new();

            for state_config in self.0.iter() {
                // This set will be used to determine which sensors have already had trip points
                // added for a given thermal state. This will let us detect if a sensor is
                // referenced by multiple trip points in the same thermal state.
                let mut sensors_configured_for_state = HashSet::new();

                for tp in state_config.trip_points.iter() {
                    ensure!(
                        sensors_configured_for_state.insert(&tp.sensor) == true,
                        "A sensor cannot be referenced by multiple trip points in the same thermal \
                        state (violated by sensor {} in state {})",
                        tp.sensor,
                        state_config.state
                    );

                    ensure!(
                        tp.activate_at >= tp.deactivate_below,
                        "activate_at must be greater or equal to deactivate_below \
                        (invalid for state {}: activate_at={}; deactivate_below={}",
                        state_config.state,
                        tp.activate_at,
                        tp.deactivate_below
                    );

                    // If we've already encountered a trip point for this sensor, make sure the new
                    // trip point has a `deactivate_below` value that is greater than the previously
                    // observed highest activate_at value. Otherwise, the new trip point will be
                    // overlapping (or otherwise non-increasing) with a previously observed trip
                    // point.
                    if let Some(activate_value) = highest_activate_value.get_mut(&tp.sensor) {
                        ensure!(
                            tp.deactivate_below > *activate_value,
                            "Trip point ranges must not overlap (range for state {} ({} - {}) \
                            overlaps with previously specified range for sensor {})",
                            state_config.state,
                            tp.deactivate_below,
                            tp.activate_at,
                            tp.sensor
                        );
                        *activate_value = tp.activate_at;
                    } else {
                        highest_activate_value.insert(tp.sensor.clone(), tp.activate_at);
                    }
                }
            }
        }

        Ok(())
    }
/// Validates the client config.
///
/// Performs a series of validations to check if the configuration defined by this
/// `ClientConfig` instance is valid. The instance is valid if:
///     1) thermal state numbers are monotonically increasing starting at 1
///     2) trip points are well-formed (`deactivate_below` <= `activate_at`)
///     3) for a given sensor, the [`deactivate_below`..=`activate_at`] range is strictly
///        increasing and non-overlapping for successive trip points
///     4) the same sensor is not referenced by multiple trip points in the same thermal state
Validates the client config.
Performs a series of validations to check if the configuration defined by this
`ClientConfig` instance is valid.
Validates the client config . Performs a series of validations to check if the configuration defined by this ` ClientConfig ` instance is valid .
fn validate(&self) -> Result<(), Error> {
        // Ensure state numbers are monotonically increasing starting at 1
        {
            let state_numbers: Vec<_> = self.0.iter().map(|s| s.state).collect();
            let expected_state_numbers: Vec<_> = (1..self.0.len() as u32 + 1).collect();
            ensure!(
                state_numbers == expected_state_numbers,
                "State numbers must increase monotonically starting at 1 \
                (got invalid state numbers: {:?})",
                state_numbers
            );
        }
        // Ensure:
        //  1) trip points are well-formed (`deactivate_below` <= `activate_at`)
        //  2) for a given sensor, the [`deactivate_below`..=`activate_at`] range is strictly
        //     increasing and non-overlapping for successive trip points
        //  3) the same sensor is not referenced by multiple trip points in the same thermal state
        {
            // This map will be used to keep track of the highest encountered `activate_at` value
            // for each sensor as we iterate through the trip points. This will let us detect if any
            // trip points are overlapping or not increasing.
            let mut highest_activate_value: HashMap<String, u32> = HashMap::new();
            for state_config in self.0.iter() {
                // This set will be used to determine which sensors have already had trip points
                // added for a given thermal state. This will let us detect if a sensor is
                // referenced by multiple trip points in the same thermal state.
                let mut sensors_configured_for_state = HashSet::new();
                for tp in state_config.trip_points.iter() {
                    ensure!(
                        sensors_configured_for_state.insert(&tp.sensor) == true,
                        "A sensor cannot be referenced by multiple trip points in the same thermal \
                        state (violated by sensor {} in state {})",
                        tp.sensor,
                        state_config.state
                    );
                    ensure!(
                        tp.activate_at >= tp.deactivate_below,
                        "activate_at must be greater or equal to deactivate_below \
                        (invalid for state {}: activate_at={}; deactivate_below={}",
                        state_config.state,
                        tp.activate_at,
                        tp.deactivate_below
                    );
                    // If we've already encountered a trip point for this sensor, make sure the new
                    // trip point has a `deactivate_below` value that is greater than the previously
                    // observed highest activate_at value. Otherwise, the new trip point will be
                    // overlapping (or otherwise non-increasing) with a previously observed trip
                    // point.
                    if let Some(activate_value) = highest_activate_value.get_mut(&tp.sensor) {
                        ensure!(
                            tp.deactivate_below > *activate_value,
                            "Trip point ranges must not overlap (range for state {} ({} - {}) \
                            overlaps with previously specified range for sensor {})",
                            state_config.state,
                            tp.deactivate_below,
                            tp.activate_at,
                            tp.sensor
                        );
                        *activate_value = tp.activate_at;
                    } else {
                        highest_activate_value.insert(tp.sensor.clone(), tp.activate_at);
                    }
                }
            }
        }
        Ok(())
    }
fn validate ( & self ) -> Result < ( ) , Error > { // Ensure state numbers are monotonically increasing starting at 1 { let state_numbers : Vec < _ > = self . 0 . iter ( ) . map ( | s | s . state ) . collect ( ) ; let expected_state_numbers : Vec < _ > = ( 1 .. self . 0 . len ( ) as u32 + 1 ) . collect ( ) ; ensure ! ( state_numbers expected_state_numbers " \
 " state_numbers ) ; } // Ensure: //  1) trip points are well-formed (`deactivate_below` <= `activate_at`) //  2) for a given sensor, the [`deactivate_below`..=`activate_at`] range is strictly //     increasing and non-overlapping for successive trip points //  3) the same sensor is not referenced by multiple trip points in the same thermal state { // This map will be used to keep track of the highest encountered `activate_at` value // for each sensor as we iterate through the trip points. This will let us detect if any // trip points are overlapping or not increasing. let mut highest_activate_value : HashMap < String , u32 > = HashMap :: new ( ) ; for state_config in self . 0 . iter ( ) { // This set will be used to determine which sensors have already had trip points // added for a given thermal state. This will let us detect if a sensor is // referenced by multiple trip points in the same thermal state. let mut sensors_configured_for_state = HashSet :: new ( ) ; for tp in state_config . trip_points . iter ( ) { ensure ! ( sensors_configured_for_state insert ( tp sensor ) true " \
 " tp sensor state_config state ) ; ensure ! ( tp activate_at tp deactivate_below " \
 " state_config state tp activate_at tp deactivate_below ) ; // If we've already encountered a trip point for this sensor, make sure the new // trip point has a `deactivate_below` value that is greater than the previously // observed highest activate_at value. Otherwise, the new trip point will be // overlapping (or otherwise non-increasing) with a previously observed trip // point. if let Some ( activate_value ) = highest_activate_value . get_mut ( & tp . sensor ) { ensure ! ( tp deactivate_below activate_value " \
 " state_config state tp deactivate_below tp activate_at tp sensor ) ; * activate_value = tp . activate_at ; } else { highest_activate_value . insert ( tp . sensor . clone ( ) , tp . activate_at ) ; } } } } Ok ( ( ) ) }
Validates the client config.
Validates the client config .
&self
&self