feat: add insert_after and insert_startup_before (#13941)

# Objective

Fixes #13866 

## Solution

Add `insert_before` in **FixedMainScheduleOrder** and
**MainScheduleOrder**, add `insert_startup_before` in
**MainScheduleOrder**, applying the same logic as `insert_after`, except
for parameters naming and insertion index.
This commit is contained in:
Alessio Marchi 2024-06-20 03:02:16 +02:00 committed by GitHub
parent 6eec73a9a5
commit 2f9c42bb33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -195,6 +195,16 @@ impl MainScheduleOrder {
self.labels.insert(index + 1, schedule.intern());
}
/// Adds the given `schedule` before the `before` schedule in the main list of schedules.
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
let index = self
.labels
.iter()
.position(|current| (**current).eq(&before))
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
self.labels.insert(index, schedule.intern());
}
/// Adds the given `schedule` after the `after` schedule in the list of startup schedules.
pub fn insert_startup_after(
&mut self,
@ -208,6 +218,20 @@ impl MainScheduleOrder {
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
self.startup_labels.insert(index + 1, schedule.intern());
}
/// Adds the given `schedule` before the `before` schedule in the list of startup schedules.
pub fn insert_startup_before(
&mut self,
before: impl ScheduleLabel,
schedule: impl ScheduleLabel,
) {
let index = self
.startup_labels
.iter()
.position(|current| (**current).eq(&before))
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
self.startup_labels.insert(index, schedule.intern());
}
}
impl Main {
@ -291,6 +315,16 @@ impl FixedMainScheduleOrder {
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
self.labels.insert(index + 1, schedule.intern());
}
/// Adds the given `schedule` before the `before` schedule
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
let index = self
.labels
.iter()
.position(|current| (**current).eq(&before))
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
self.labels.insert(index, schedule.intern());
}
}
impl FixedMain {