bingus 0.10.0

databending made easy
Documentation
use std::{borrow::Cow, convert::Infallible};

use cfg_if::cfg_if;
#[cfg(feature = "rayon")]
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};

use crate::{Bendable, Bytes, IntoDataBytes, TryFromDataBytes};

impl IntoDataBytes for Bytes {
    fn into_data_bytes(self) -> Bytes {
        self
    }
}

impl TryFromDataBytes for Bytes {
    type Error = Infallible;
    type Format = ();
    fn try_from_data_bytes(
        bytes: Bytes,
        _: Self::Format,
        _: crate::Crop,
    ) -> Result<Self, Self::Error> {
        Ok(bytes)
    }
}

impl Bendable for Bytes {
    type Unit = u8;
    fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
        cfg_if! {
        if #[cfg(feature = "rayon")] {
            let iter = self.par_iter_mut();
        } else {
            let iter = self.iter_mut();
        }
        }
        iter.for_each(|e| *e = f(Cow::Borrowed(e)));
        self
    }
}