use crate::pass::Pass;
pub struct Schedule<C> {
passes: Vec<Box<dyn Pass<Ctx = C> + Send + Sync>>,
}
impl<C> Schedule<C> {
pub fn new() -> Self {
Self { passes: Vec::new() }
}
pub fn push<P>(&mut self, pass: P)
where
P: Pass<Ctx = C> + Send + Sync + 'static,
{
self.passes.push(Box::new(pass));
}
pub fn push_boxed(&mut self, pass: Box<dyn Pass<Ctx = C> + Send + Sync>) {
self.passes.push(pass);
}
pub fn len(&self) -> usize {
self.passes.len()
}
pub fn is_empty(&self) -> bool {
self.passes.is_empty()
}
pub fn pass_name(&self, round: usize) -> Option<&'static str> {
self.passes.get(round).map(|p| p.name())
}
pub(crate) fn pass_at(&self, round: usize) -> Option<&(dyn Pass<Ctx = C> + Send + Sync)> {
self.passes.get(round).map(|p| p.as_ref())
}
}
impl<C> Default for Schedule<C> {
fn default() -> Self {
Self::new()
}
}
impl<C> std::fmt::Debug for Schedule<C> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Schedule")
.field("passes", &self.passes.len())
.finish()
}
}