use std::fmt::{self, Debug};
use std::vec::IntoIter;
use crate::scheduler::engine::Tag;
use super::Step;
mod convert;
pub use convert::IntoSteps;
pub struct Steps<I, C = ()> {
inner: Vec<Step<I, C>>,
}
#[allow(clippy::must_use_candidate)]
impl<I, C> Steps<I, C> {
#[inline]
pub fn len(&self) -> usize {
self.inner.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}
impl<I, C> Tag<I, C> for Steps<I, C> {
type Target<T> = Steps<I, T>;
#[inline]
fn tag<T>(self) -> Self::Target<T> {
Steps {
inner: self.inner.into_iter().map(Step::tag).collect(),
}
}
}
impl<I> From<()> for Steps<I> {
#[inline]
fn from((): ()) -> Self {
Self::default()
}
}
impl<I, C> From<Step<I, C>> for Steps<I, C> {
#[inline]
fn from(value: Step<I, C>) -> Self {
Self::from_iter(Some(value))
}
}
impl<I, C> From<Option<Step<I, C>>> for Steps<I, C> {
#[inline]
fn from(value: Option<Step<I, C>>) -> Self {
Self::from_iter(value)
}
}
impl<I, C, const N: usize> From<[Step<I, C>; N]> for Steps<I, C> {
#[inline]
fn from(value: [Step<I, C>; N]) -> Self {
Self::from_iter(value)
}
}
impl<I, C> From<Vec<Step<I, C>>> for Steps<I, C> {
#[inline]
fn from(value: Vec<Step<I, C>>) -> Self {
Self::from_iter(value)
}
}
impl<I, C> FromIterator<Step<I, C>> for Steps<I, C> {
#[inline]
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = Step<I, C>>,
{
Self {
inner: iter.into_iter().collect(),
}
}
}
impl<I, C> IntoIterator for Steps<I, C> {
type Item = Step<I, C>;
type IntoIter = IntoIter<Self::Item>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}
impl<I, C> Default for Steps<I, C> {
#[inline]
fn default() -> Self {
Self { inner: Vec::default() }
}
}
impl<I, C> Debug for Steps<I, C>
where
I: Debug,
C: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list().entries(self.inner.iter()).finish()
}
}