orx-parallel 4.0.0

Performant parallel computations with an expressive iterator API.
Documentation
use crate::infallible::XapEnumByInput;
use crate::infallible::xap::Xap;
use crate::sizes::One;
use core::marker::PhantomData;

/// Identity xap that returns the input unchanged.
pub struct Id<I>(PhantomData<I>);

impl<I> Clone for Id<I> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<I> Copy for Id<I> {}

unsafe impl<I> Send for Id<I> {}

impl<I> Id<I> {
    /// Creates an identity xap.
    pub const fn new() -> Self {
        Self(PhantomData)
    }
}

impl<I> Default for Id<I> {
    fn default() -> Self {
        Self::new()
    }
}

impl<I> XapEnumByInput for Id<I> {
    type Enumerated = Id<(usize, I)>;

    fn enumerate(self) -> Self::Enumerated {
        Id::new()
    }
}

impl<I> Xap for Id<I> {
    type I = I;

    type O = I;

    type Size = One;

    type Values = [I; 1];

    fn xap(&self, i: Self::I) -> Self::Values {
        [i]
    }
}