fn generate(&mut self) -> Result<bool, RRuleError> {
        // If there already was an error, return the error again.
        if let Some(err) = self.get_err() {
            return Err(err.clone());
        }
        // Do early check if done (if known)
        if self.finished {
            return Ok(true);
        }
        // Check if the count is set, and if 0
        match self.count {
            Some(count) if count == 0 => return Ok(true),
            _ => (),
        };

        // Get general info about recurrence rules
        let rrule = self.ii.get_rrule();

        if rrule.interval == 0 {
            return Ok(true);
        }

        // If `counter_date` is later than `until` date, we can stop
        if let Some(until) = &rrule.until {
            if &self.counter_date > until {
                return Ok(false);
            }
        }
        let mut loop_counter: u32 = 0;

        // Loop until there is at least 1 item in the buffer.
        while self.buffer.is_empty() {
            let rrule = self.ii.get_rrule();

            // Prevent infinite loops
            loop_counter += 1;
            if loop_counter >= MAX_ITER_LOOP {
                return Err(RRuleError::new_iter_err(format!(
                    "Reached max loop counter (`{}`). \
                    See 'validator limits' in docs for more info.",
                    MAX_ITER_LOOP
                )));
            }

            #[allow(clippy::cast_possible_truncation)]
            let (dayset, start, end) = self.ii.get_dayset(
                rrule.freq,
                self.counter_date.year(),
                self.counter_date.month() as u8,
                self.counter_date.day() as u8,
            )?;

            // If `counter_date` is later than `until` date, we can stop
            if let Some(until) = &rrule.until {
                if &self.counter_date > until {
                    return Ok(false);
                }
            }

            // Change `Vec<u64>` to `Vec<Option<u64>>`
            let mut dayset = dayset.into_iter().map(Some).collect::<Vec<Option<u64>>>();

            let filtered = remove_filtered_days(&mut dayset, start, end, &self.ii);

            #[allow(clippy::cast_possible_truncation)]
            // Change `Vec<Option<u64>>` to `Vec<Option<i32>>`
            let dayset = dayset
                .into_iter()
                .map(|day| day.map(|day| day as i32))
                .collect::<Vec<Option<i32>>>();

            #[allow(clippy::cast_possible_truncation)]
            if rrule.by_set_pos.is_empty() {
                // Loop over `start..end`
                for current_day in dayset.iter().take(end as usize).skip(start as usize) {
                    if current_day.is_none() {
                        continue;
                    }

                    let current_day = current_day.unwrap();
                    let year_ordinal = self.ii.year_ordinal().unwrap();
                    // Ordinal conversion uses UTC: if we apply local-TZ here, then
                    // just below we'll end up double-applying.
                    let date = from_ordinal(year_ordinal + i64::from(current_day));
                    // We apply the local-TZ here,
                    let date = self
                        .dt_start
                        .timezone()
                        .ymd(date.year(), date.month(), date.day());
                    for timeset in &self.timeset {
                        let res = date
                            .and_hms_opt(0, 0, 0)
                            .ok_or_else(|| RRuleError::new_iter_err("Invalid datetime."))?
                            .checked_add_signed(timeset.duration_from_midnight())
                            .ok_or_else(|| RRuleError::new_iter_err("Invalid datetime."))?;

                        if rrule.until.is_some() && res > rrule.until.unwrap() {
                            return Ok(true);
                        }
                        if res >= self.dt_start {
                            self.buffer.push_back(res);

                            if let Some(count) = self.count {
                                if count > 0 {
                                    self.count = Some(count - 1);
                                    // self.ii.get_rrule().count = Some(count - 1);
                                }
                                // This means that the real count is 0, because of the decrement above
                                if count == 1 {
                                    return Ok(true);
                                }
                            }
                        }
                    }
                }
            } else {
                let pos_list = build_pos_list(
                    &rrule.by_set_pos,
                    &self.timeset,
                    start,
                    end,
                    &self.ii,
                    &dayset,
                    self.dt_start.timezone(),
                )?;

                for res in pos_list {
                    if rrule.until.is_some() && res > rrule.until.unwrap() {
                        continue; // or break ?
                    }

                    if res >= self.dt_start {
                        self.buffer.push_back(res);

                        if let Some(count) = self.count {
                            if count > 0 {
                                self.count = Some(count - 1);
                                // self.ii.get_rrule().count = Some(count - 1);
                            }
                            // This means that the real count is 0, because of the decrement above
                            if count == 1 {
                                return Ok(true);
                            }
                        }
                    }
                }
            }

            // Handle frequency and interval
            self.counter_date = increment_counter_date(self.counter_date, rrule, filtered)?;

            #[allow(clippy::cast_possible_truncation)]
            if rrule.freq == Frequency::Hourly
                || rrule.freq == Frequency::Minutely
                || rrule.freq == Frequency::Secondly
            {
                self.timeset = self.ii.get_timeset(
                    rrule.freq,
                    self.counter_date.hour() as u8,
                    self.counter_date.minute() as u8,
                    self.counter_date.second() as u8,
                    0,
                )?;
            }

            let year = self.counter_date.year();
            #[allow(clippy::cast_possible_truncation)]
            let month = self.counter_date.month() as u8;

            self.ii.rebuild(year, month)?;
        }
        // Indicate that there might be more items on the next iteration.
        Ok(false)
    }
// TODO: This function is too long.
This function is too long.
This function is too long .
fn generate(&mut self) -> Result<bool, RRuleError> {
        // If there already was an error, return the error again.
        if let Some(err) = self.get_err() {
            return Err(err.clone());
        }
        // Do early check if done (if known)
        if self.finished {
            return Ok(true);
        }
        // Check if the count is set, and if 0
        match self.count {
            Some(count) if count == 0 => return Ok(true),
            _ => (),
        };
        // Get general info about recurrence rules
        let rrule = self.ii.get_rrule();
        if rrule.interval == 0 {
            return Ok(true);
        }
        // If `counter_date` is later than `until` date, we can stop
        if let Some(until) = &rrule.until {
            if &self.counter_date > until {
                return Ok(false);
            }
        }
        let mut loop_counter: u32 = 0;
        // Loop until there is at least 1 item in the buffer.
        while self.buffer.is_empty() {
            let rrule = self.ii.get_rrule();
            // Prevent infinite loops
            loop_counter += 1;
            if loop_counter >= MAX_ITER_LOOP {
                return Err(RRuleError::new_iter_err(format!(
                    "Reached max loop counter (`{}`). \
                    See 'validator limits' in docs for more info.",
                    MAX_ITER_LOOP
                )));
            }
            #[allow(clippy::cast_possible_truncation)]
            let (dayset, start, end) = self.ii.get_dayset(
                rrule.freq,
                self.counter_date.year(),
                self.counter_date.month() as u8,
                self.counter_date.day() as u8,
            )?;
            // If `counter_date` is later than `until` date, we can stop
            if let Some(until) = &rrule.until {
                if &self.counter_date > until {
                    return Ok(false);
                }
            }
            // Change `Vec<u64>` to `Vec<Option<u64>>`
            let mut dayset = dayset.into_iter().map(Some).collect::<Vec<Option<u64>>>();
            let filtered = remove_filtered_days(&mut dayset, start, end, &self.ii);
            #[allow(clippy::cast_possible_truncation)]
            // Change `Vec<Option<u64>>` to `Vec<Option<i32>>`
            let dayset = dayset
                .into_iter()
                .map(|day| day.map(|day| day as i32))
                .collect::<Vec<Option<i32>>>();
            #[allow(clippy::cast_possible_truncation)]
            if rrule.by_set_pos.is_empty() {
                // Loop over `start..end`
                for current_day in dayset.iter().take(end as usize).skip(start as usize) {
                    if current_day.is_none() {
                        continue;
                    }
                    let current_day = current_day.unwrap();
                    let year_ordinal = self.ii.year_ordinal().unwrap();
                    // Ordinal conversion uses UTC: if we apply local-TZ here, then
                    // just below we'll end up double-applying.
                    let date = from_ordinal(year_ordinal + i64::from(current_day));
                    // We apply the local-TZ here,
                    let date = self
                        .dt_start
                        .timezone()
                        .ymd(date.year(), date.month(), date.day());
                    for timeset in &self.timeset {
                        let res = date
                            .and_hms_opt(0, 0, 0)
                            .ok_or_else(|| RRuleError::new_iter_err("Invalid datetime."))?
                            .checked_add_signed(timeset.duration_from_midnight())
                            .ok_or_else(|| RRuleError::new_iter_err("Invalid datetime."))?;
                        if rrule.until.is_some() && res > rrule.until.unwrap() {
                            return Ok(true);
                        }
                        if res >= self.dt_start {
                            self.buffer.push_back(res);
                            if let Some(count) = self.count {
                                if count > 0 {
                                    self.count = Some(count - 1);
                                    // self.ii.get_rrule().count = Some(count - 1);
                                }
                                // This means that the real count is 0, because of the decrement above
                                if count == 1 {
                                    return Ok(true);
                                }
                            }
                        }
                    }
                }
            } else {
                let pos_list = build_pos_list(
                    &rrule.by_set_pos,
                    &self.timeset,
                    start,
                    end,
                    &self.ii,
                    &dayset,
                    self.dt_start.timezone(),
                )?;
                for res in pos_list {
                    if rrule.until.is_some() && res > rrule.until.unwrap() {
                        continue; // or break ?
                    }
                    if res >= self.dt_start {
                        self.buffer.push_back(res);
                        if let Some(count) = self.count {
                            if count > 0 {
                                self.count = Some(count - 1);
                                // self.ii.get_rrule().count = Some(count - 1);
                            }
                            // This means that the real count is 0, because of the decrement above
                            if count == 1 {
                                return Ok(true);
                            }
                        }
                    }
                }
            }
            // Handle frequency and interval
            self.counter_date = increment_counter_date(self.counter_date, rrule, filtered)?;
            #[allow(clippy::cast_possible_truncation)]
            if rrule.freq == Frequency::Hourly
                || rrule.freq == Frequency::Minutely
                || rrule.freq == Frequency::Secondly
            {
                self.timeset = self.ii.get_timeset(
                    rrule.freq,
                    self.counter_date.hour() as u8,
                    self.counter_date.minute() as u8,
                    self.counter_date.second() as u8,
                    0,
                )?;
            }
            let year = self.counter_date.year();
            #[allow(clippy::cast_possible_truncation)]
            let month = self.counter_date.month() as u8;
            self.ii.rebuild(year, month)?;
        }
        // Indicate that there might be more items on the next iteration.
        Ok(false)
    }
fn generate ( & mut self ) -> Result < bool , RRuleError > { // If there already was an error, return the error again. if let Some ( err ) = self . get_err ( ) { return Err ( err . clone ( ) ) ; } // Do early check if done (if known) if self . finished { return Ok ( true ) ; } // Check if the count is set, and if 0 match self . count { Some ( count ) if count == 0 => return Ok ( true ) , _ => ( ) , } ; // Get general info about recurrence rules let rrule = self . ii . get_rrule ( ) ; if rrule . interval == 0 { return Ok ( true ) ; } // If `counter_date` is later than `until` date, we can stop if let Some ( until ) = & rrule . until { if & self . counter_date > until { return Ok ( false ) ; } } let mut loop_counter : u32 = 0 ; // Loop until there is at least 1 item in the buffer. while self . buffer . is_empty ( ) { let rrule = self . ii . get_rrule ( ) ; // Prevent infinite loops loop_counter += 1 ; if loop_counter >= MAX_ITER_LOOP { return Err ( RRuleError :: new_iter_err ( format ! ( " \
 " MAX_ITER_LOOP ) ) ) ; } # [ allow ( clippy cast_possible_truncation ) ] let ( dayset , start , end ) = self . ii . get_dayset ( rrule . freq , self . counter_date . year ( ) , self . counter_date . month ( ) as u8 , self . counter_date . day ( ) as u8 , ) ? ; // If `counter_date` is later than `until` date, we can stop if let Some ( until ) = & rrule . until { if & self . counter_date > until { return Ok ( false ) ; } } // Change `Vec<u64>` to `Vec<Option<u64>>` let mut dayset = dayset . into_iter ( ) . map ( Some ) . collect :: < Vec < Option < u64 > > > ( ) ; let filtered = remove_filtered_days ( & mut dayset , start , end , & self . ii ) ; # [ allow ( clippy cast_possible_truncation ) ] // Change `Vec<Option<u64>>` to `Vec<Option<i32>>` let dayset = dayset . into_iter ( ) . map ( | day | day . map ( | day | day as i32 ) ) . collect :: < Vec < Option < i32 > > > ( ) ; # [ allow ( clippy cast_possible_truncation ) ] if rrule . by_set_pos . is_empty ( ) { // Loop over `start..end` for current_day in dayset . iter ( ) . take ( end as usize ) . skip ( start as usize ) { if current_day . is_none ( ) { continue ; } let current_day = current_day . unwrap ( ) ; let year_ordinal = self . ii . year_ordinal ( ) . unwrap ( ) ; // Ordinal conversion uses UTC: if we apply local-TZ here, then // just below we'll end up double-applying. let date = from_ordinal ( year_ordinal + i64 :: from ( current_day ) ) ; // We apply the local-TZ here, let date = self . dt_start . timezone ( ) . ymd ( date . year ( ) , date . month ( ) , date . day ( ) ) ; for timeset in & self . timeset { let res = date . and_hms_opt ( 0 , 0 , 0 ) . ok_or_else ( | | RRuleError :: new_iter_err ( " " ) ) ? . checked_add_signed ( timeset . duration_from_midnight ( ) ) . ok_or_else ( | | RRuleError :: new_iter_err ( " " ) ) ? ; if rrule . until . is_some ( ) && res > rrule . until . unwrap ( ) { return Ok ( true ) ; } if res >= self . dt_start { self . buffer . push_back ( res ) ; if let Some ( count ) = self . count { if count > 0 { self . count = Some ( count - 1 ) ; // self.ii.get_rrule().count = Some(count - 1); } // This means that the real count is 0, because of the decrement above if count == 1 { return Ok ( true ) ; } } } } } } else { let pos_list = build_pos_list ( & rrule . by_set_pos , & self . timeset , start , end , & self . ii , & dayset , self . dt_start . timezone ( ) , ) ? ; for res in pos_list { if rrule . until . is_some ( ) && res > rrule . until . unwrap ( ) { continue ; // or break ? } if res >= self . dt_start { self . buffer . push_back ( res ) ; if let Some ( count ) = self . count { if count > 0 { self . count = Some ( count - 1 ) ; // self.ii.get_rrule().count = Some(count - 1); } // This means that the real count is 0, because of the decrement above if count == 1 { return Ok ( true ) ; } } } } } // Handle frequency and interval self . counter_date = increment_counter_date ( self . counter_date , rrule , filtered ) ? ; # [ allow ( clippy cast_possible_truncation ) ] if rrule . freq == Frequency :: Hourly || rrule . freq == Frequency :: Minutely || rrule . freq == Frequency :: Secondly { self . timeset = self . ii . get_timeset ( rrule . freq , self . counter_date . hour ( ) as u8 , self . counter_date . minute ( ) as u8 , self . counter_date . second ( ) as u8 , 0 , ) ? ; } let year = self . counter_date . year ( ) ; # [ allow ( clippy cast_possible_truncation ) ] let month = self . counter_date . month ( ) as u8 ; self . ii . rebuild ( year , month ) ? ; } // Indicate that there might be more items on the next iteration. Ok ( false ) }
TODO: This function is too long.
TODO : This function is too long .
&mut self
&mut self